[R] Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"

2017-09-25 Thread Chris Evans
I am hitting an odd message "Error in FUN(newX[, i], ...) : all arguments must 
have the same length".  I can't supply the data as it's a huge data frame but I 
think this has enough diagnostic information to show the issue.  I am sure I am 
missing something obvious.  I've put some extra comments in but otherwise this 
is cut and pasted from Rstudio.

### I wanted a table of the values in four columns:
> apply(datTAF[,75:78],2,table,na.rm=TRUE)
Error in FUN(newX[, i], ...) : all arguments must have the same length

### odd, surely as it's a data frame all x going into table() should be same 
length. Check:
> apply(datTAF[,75:78],2,length)
 RiskSuicide RiskSelfHarm  RiskHarmOthRiskLegal 
3009 3009 3009 3009 

### I has reasons to think the tables should all be the same length.  Check:
> apply(datTAF[,75:78],2,function(x){length(table(x))})
 RiskSuicide RiskSelfHarm  RiskHarmOthRiskLegal 
   6666 

### Now I'm a bit baffled.  Try str:
> apply(datTAF[,75:78],2,str)
 Named chr [1:3009] "." "." "." "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" 
"0" "0" "0" "0" "." ...
 - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ...
 Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "1" "0" "0" "0" "0" "0" "." "0" 
"0" "0" "0" "0" "." ...
 - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ...
 Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" 
"0" "0" "0" "0" "." ...
 - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ...
 Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" 
"0" "0" "0" "0" "." ...
 - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ...
NULL

### Not sure where that trailing "NULL" came from:
> str(datTAF[,78])
 chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" "0" 
"0" "0" "0" "." "0" ...

> Sys.info()
   sysnamereleaseversion   nodenamemachine  
login 
 "Windows" ">= 8 x64"   "build 9200"  "HPLP166"   "x86-64"  
"Chris.Evans" 
  user effective_user 
 "Chris.Evans"  "Chris.Evans" 

Anyone see what I'm missing?  TIA,

Chris

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fw: passing different sample sizes

2017-09-25 Thread Bert Gunter
Your code is full of syntactic errors. What do you think 1.71(se) means?

After you clean up your code, something like this might be what you want:

out <- lapply(seq(40,500,by = 25), f)

To get plots, just stick in a plot statement after you define m and d.

Have you gone through any R tutorials? You seem to be confused about basics
that tutorials could help you with.  This list is not meant to replace such
homework on your own.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 3:28 PM, Farnoosh Sheikhi 
wrote:

> Hi Bert,
>
> Here is the code:
> f<-function(n){
> m=runif(n, 50, 100)
> d=rnorm(n, 0, 1)
> se=sd(d)/sqrt (n)
>
> ci.u<-mean(d)+1.96*sd(d)
> ci.l<-mean(d)-1.96*sd(d)
> ci.w<-ci.u-ci.l
>
> w.ci.uu<-ci.u+(qt (0.975, df=n-1)*1.71(se)
> w.ci.ul<-ci.u-(qt (0.975, df=n-1)*1.71(se)
> w.ci.upper<-w.ci.uu-w.ci.ul
>
> w.ci.lu<-ci.l+(qt (0.975, df=n-1)*1.71(se)
> w.ci.ll<-ci.l-(qt (0.975, df=n-1)*1.71(se)
> w.ci.lower<-w.ci.lu-w.ci.ll
>
>   res<-as.data.frame(cbind(n, ci.u, ci.l, ci.w, w.ci.upper, w.ci.lower))
>   return(res)
> }
>
>
> I would like to pass different sample sizes n<-seq(40, 500, by=25) and add
> a scatter plot for each n.
> plot(m~d)
>
> Thanks.
>
>
>
> On Monday, September 25, 2017 3:00 PM, Bert Gunter 
> wrote:
>
>
> 1. 2o is gibberish; 20 is the number of fingers and toes most of us have.
>
> 2. This is a plain text list. Your code became gibberish with your HTML
> post.
>
> Cheers,
> Bert
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Sep 25, 2017 at 2:16 PM, Farnoosh Sheikhi via R-help <
> r-help@r-project.org> wrote:
>
>
>
>
>
> Hi,
> I have the below function which returns confidence intervals. I wanted to
> pass different sample sizes through the function, but for some reason it's
> not working. n   <- seq(from=40, to=300, by=2o)
>
> I was also wondering how I can return a plot for different sample
> sizes. plot(m~d, main="n(i)")
> Any help or suggestion is appreciated.
>
>
> f< -function(n){  m = runif(n,50,200)  d =
>  rnorm(n,0,1)   ci.u<-mean(d)+1.96*sd(d)  ci.l<-mean(d)-1.96*sd(d)
> ci.w<-ci.u-ci.lse=sd(d)/sqrt(n)  w.ci.uu<-ci.u+(qt(.975,
> df=n-1))*1.71*se  w.ci.ul<-ci.u-(qt(.975, df=n-1))*1.71*se
> w.ci.upper<-w.ci.uu- w.ci.ulw.ci.lu<-ci.l+(qt(. 975,
> df=n-1))*1.71*se  w.ci.ll<-ci.l-(qt(.975, df=n-1))*1.71*se
> w.ci.lower<-w.ci.lu- w.ci.llres<-as.data.frame(cbind(n, ci.u, ci.l,
> ci.w, w.ci.upper, w.ci.lower))  return(res)} Best,Nooshi
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> __ 
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/ listinfo/r-help
> 
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fw: passing different sample sizes

2017-09-25 Thread Bert Gunter
1. 2o is gibberish; 20 is the number of fingers and toes most of us have.

2. This is a plain text list. Your code became gibberish with your HTML
post.

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 2:16 PM, Farnoosh Sheikhi via R-help <
r-help@r-project.org> wrote:

>
>
>
>
> Hi,
> I have the below function which returns confidence intervals. I wanted to
> pass different sample sizes through the function, but for some reason it's
> not working. n   <- seq(from=40, to=300, by=2o)
>
> I was also wondering how I can return a plot for different sample
> sizes. plot(m~d, main="n(i)")
> Any help or suggestion is appreciated.
>
>
> f<-function(n){  m = runif(n,50,200)  d =
>  rnorm(n,0,1)   ci.u<-mean(d)+1.96*sd(d)  ci.l<-mean(d)-1.96*sd(d)
> ci.w<-ci.u-ci.lse=sd(d)/sqrt(n)  w.ci.uu<-ci.u+(qt(.975,
> df=n-1))*1.71*se  w.ci.ul<-ci.u-(qt(.975, df=n-1))*1.71*se
> w.ci.upper<-w.ci.uu- w.ci.ulw.ci.lu<-ci.l+(qt(.975, df=n-1))*1.71*se
> w.ci.ll<-ci.l-(qt(.975, df=n-1))*1.71*se  w.ci.lower<-w.ci.lu- w.ci.ll
> res<-as.data.frame(cbind(n, ci.u, ci.l, ci.w, w.ci.upper, w.ci.lower))
> return(res)} Best,Nooshi
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Fw: passing different sample sizes

2017-09-25 Thread Farnoosh Sheikhi via R-help




Hi, 
I have the below function which returns confidence intervals. I wanted to pass 
different sample sizes through the function, but for some reason it's not 
working. n   <- seq(from=40, to=300, by=2o)

I was also wondering how I can return a plot for different sample sizes. 
plot(m~d, main="n(i)") 
Any help or suggestion is appreciated.


f<-function(n){  m = runif(n,50,200)  d =  
rnorm(n,0,1)   ci.u<-mean(d)+1.96*sd(d)  ci.l<-mean(d)-1.96*sd(d)  
ci.w<-ci.u-ci.l    se=sd(d)/sqrt(n)  w.ci.uu<-ci.u+(qt(.975, df=n-1))*1.71*se  
w.ci.ul<-ci.u-(qt(.975, df=n-1))*1.71*se  w.ci.upper<-w.ci.uu- w.ci.ul
w.ci.lu<-ci.l+(qt(.975, df=n-1))*1.71*se  w.ci.ll<-ci.l-(qt(.975, 
df=n-1))*1.71*se  w.ci.lower<-w.ci.lu- w.ci.ll    res<-as.data.frame(cbind(n, 
ci.u, ci.l, ci.w, w.ci.upper, w.ci.lower))  return(res)} Best,Nooshi





[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Sample of a subsample

2017-09-25 Thread Bert Gunter
Yes.

Beating a pretty weary horse, a slightly cleaner version of my prior
offering using with(), instead of within() is:

with(dat,
dat[sampleNo[sample(var1[!var1%%2 & !sampleNo], 10, rep=FALSE)],
"sampleNo"] <- 2)

with() and within() are convenient ways to avoid having to repeatedly name
the columns via $  . Note also the use of logical subscripting of the data
frame in which numeric 0 is coerced to FALSE and any nonzero value to TRUE
(which I should have done previously).

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 11:43 AM, Eric Berger  wrote:

> Hi David,
> I was about to post a reply when Bert responded. His answer is good
> and his comment to use the name 'dat' rather than 'data' is instructive.
> I am providing my suggestion as well because I think it may address
> what was causing you some confusion (mainly to use "which", but also
> the missing !)
>
> idx2 <- sample( which( (!data$var1%%2) & data$sampleNo==0 ), size=10,
> replace=F)
> data[idx2,]$sampleNo <- 2
>
> Eric
>
>
>
> On Mon, Sep 25, 2017 at 9:03 PM, Bert Gunter 
> wrote:
>
>> For personal aesthetic reasons, I changed the name "data" to "dat".
>>
>> Your code, with a slight modification:
>>
>> set.seed (1357)  ## for reproducibility
>> dat <- data.frame(var1=seq(1:40), var2=seq(40,1))
>> dat$sampleNo <- 0
>> idx <- sample(seq(1,nrow(dat)), size=10, replace=F)
>> dat[idx,"sampleNo"] <-1
>>
>> ## yielding
>> > dat
>>
>>var1 var2 sampleNo
>> 1 1   400
>> 2 2   391
>> 3 3   380
>> 4 4   370
>> 5 5   360
>> 6 6   351
>> 7 7   340
>> 8 8   330
>> 9 9   320
>> 10   10   310
>> 11   11   300
>> 12   12   290
>> 13   13   280
>> 14   14   270
>> 15   15   261
>> 16   16   251
>> 17   17   240
>> 18   18   230
>> 19   19   220
>> 20   20   211
>> 21   21   200
>> 22   22   191
>> 23   23   180
>> 24   24   171
>> 25   25   160
>> 26   26   151
>> 27   27   140
>> 28   28   130
>> 29   29   120
>> 30   30   110
>> 31   31   100
>> 32   3290
>> 33   3380
>> 34   3470
>> 35   3561
>> 36   3650
>> 37   3741
>> 38   3830
>> 39   3920
>> 40   4010
>>
>> ## This is basically a transcription of your specification into indexing
>> logic
>>
>> dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
>> sampleNo==0],10,rep=FALSE)] <- 2)
>>
>> ##yielding
>> > dat
>>
>>var1 var2 sampleNo
>> 1 1   400
>> 2 2   391
>> 3 3   380
>> 4 4   372
>> 5 5   360
>> 6 6   351
>> 7 7   340
>> 8 8   332
>> 9 9   320
>> 10   10   312
>> 11   11   300
>> 12   12   290
>> 13   13   280
>> 14   14   272
>> 15   15   261
>> 16   16   251
>> 17   17   240
>> 18   18   232
>> 19   19   220
>> 20   20   211
>> 21   21   200
>> 22   22   191
>> 23   23   180
>> 24   24   171
>> 25   25   160
>> 26   26   151
>> 27   27   140
>> 28   28   132
>> 29   29   120
>> 30   30   112
>> 31   31   100
>> 32   3292
>> 33   3380
>> 34   3472
>> 35   3561
>> 36   3652
>> 37   3741
>> 38   3830
>> 39   3920
>> 40   4010
>>
>>
>>
>>
>>
>> dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
>> sampleNo==0],10,rep=FALSE)] <- 2)
>>
>>
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and
>> sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Mon, Sep 25, 2017 at 10:27 AM, David Studer 
>> wrote:
>>
>> > Hello everybody!
>> >
>> > I have the following problem: I'd like to select a sample from a
>> subsample
>> > in a dataset. Actually, I don't want to select it, but to create a new
>> > variable sampleNo that indicates to which sample (one or two) a case
>> > belongs to.
>> >
>> > Lets suppose I have a dataset containing 40 cases:
>> >
>> > data <- data.frame(var1=seq(1:40), var2=seq(40,1))
>> >
>> > The first sample (n=10) I drew like this:
>> >
>> > data$sampleNo <- 0
>> > idx <- sample(seq(1,nrow(data)), size=10, replace=F)
>> > data[idx,]$sampleNo <- 1
>> >
>> > Now, (and here my problems start) I'd like to draw a second sample
>> (n=10).
>> > But this sample should be drawn from the cases that don't belong to the
>> > first sample only. *Add

Re: [R] bowed linear approximations

2017-09-25 Thread Fox, John
Dear Rich,

Assuming that I understand what you want to do, try adding the following to 
your script (which, by the way, is more complicated that it needs to be):

xx <- 10:50
m <- lm(y ~ x)
yy <- predict(m, data.frame(x=xx))
lines(spline(xx, yy), col="blue")

m <- lm(y ~ log(x))
yy <- predict(m, data.frame(x=xx))
points(xx, yy, col="magenta")

The first set of commands adds a line corresponding to the points that you 
plotted, which if I understand right, is *not* what you want. The second set of 
commands shows how to find points along the diagonal straight line that you 
plotted, given their x-values, which is what I think you want.

If you examine the linear models fit, you'll see that they just interpolate 
between the two points, albeit differently.

I hope this helps,
 John

-
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socserv.mcmaster.ca/jfox




> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Evans,
> Richard K. (GRC-H000)
> Sent: Monday, September 25, 2017 3:28 PM
> To: r-help@r-project.org
> Subject: [R] bowed linear approximations
> 
> Hello,
> 
> Please run the following code snippet and note the resulting plot:
> 
> x <- c(10, 50)
> y <- c(0.983, 0.7680123)
> plot(x,y,type="b",log="x")
> for(i in 1:50){
>  xx <- exp(runif(1,log(min(x)),log(max(x)) )) yy <- approx(x,y,xout=xx, 
> method =
> "linear")
> points(xx,yy$y)
> }
> 
> notice the "log=x" plot parameter and the resulting "bow" in the linear
> approximation.
> 
> This makes sense when I realized that the plot command is first making the
> plot and then drawing straight lines between points on a log plot AFTER the
> plot is generated and that that's why the line is straight. I get that.
> .. and it also makes sense that the bowed points are a result of the linear
> approximations being made BEFORE plotted in a logarithmic plot. I get that..
> 
> My goal is to make approximations that lie on the line produced on the plot as
> shown, so I realize that what I want to do is NOT linear approximations, but
> maybe "log" approximations?
> However, the approximation methods are only "linear" and "constant" .. there
> isn't a "log" method to approximate with.
> 
> So can anyone tell me how to fix the code such that he approximated points
> DO lie on the line as plotted with the "log=x" plot parameter?
> Oh, and they have to be uniformly distributed along the Log=x axis.. I think
> that's the tricky part.
> 
> Any help and/or insight would be greatly appreciated.
> 
> Thank you!
> -Rich
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] bowed linear approximations

2017-09-25 Thread Evans, Richard K. (GRC-H000)
Hello,

Please run the following code snippet and note the resulting plot:

x <- c(10, 50)
y <- c(0.983, 0.7680123)
plot(x,y,type="b",log="x")
for(i in 1:50){
 xx <- exp(runif(1,log(min(x)),log(max(x)) ))
yy <- approx(x,y,xout=xx, method = "linear")
points(xx,yy$y)
}

notice the "log=x" plot parameter and the resulting "bow" in the linear 
approximation.

This makes sense when I realized that the plot command is first making the plot 
and then drawing straight lines between points on a log plot AFTER the plot is 
generated and that that's why the line is straight. I get that.
.. and it also makes sense that the bowed points are a result of the linear 
approximations being made BEFORE plotted in a logarithmic plot. I get that..

My goal is to make approximations that lie on the line produced on the plot as 
shown, so I realize that what I want to do is NOT linear approximations, but 
maybe "log" approximations?
However, the approximation methods are only "linear" and "constant" .. there 
isn't a "log" method to approximate with.

So can anyone tell me how to fix the code such that he approximated points DO 
lie on the line as plotted with the "log=x" plot parameter?
Oh, and they have to be uniformly distributed along the Log=x axis.. I think 
that's the tricky part.

Any help and/or insight would be greatly appreciated.

Thank you!
-Rich


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sample of a subsample

2017-09-25 Thread Eric Berger
Hi David,
I was about to post a reply when Bert responded. His answer is good
and his comment to use the name 'dat' rather than 'data' is instructive.
I am providing my suggestion as well because I think it may address
what was causing you some confusion (mainly to use "which", but also
the missing !)

idx2 <- sample( which( (!data$var1%%2) & data$sampleNo==0 ), size=10,
replace=F)
data[idx2,]$sampleNo <- 2

Eric



On Mon, Sep 25, 2017 at 9:03 PM, Bert Gunter  wrote:

> For personal aesthetic reasons, I changed the name "data" to "dat".
>
> Your code, with a slight modification:
>
> set.seed (1357)  ## for reproducibility
> dat <- data.frame(var1=seq(1:40), var2=seq(40,1))
> dat$sampleNo <- 0
> idx <- sample(seq(1,nrow(dat)), size=10, replace=F)
> dat[idx,"sampleNo"] <-1
>
> ## yielding
> > dat
>
>var1 var2 sampleNo
> 1 1   400
> 2 2   391
> 3 3   380
> 4 4   370
> 5 5   360
> 6 6   351
> 7 7   340
> 8 8   330
> 9 9   320
> 10   10   310
> 11   11   300
> 12   12   290
> 13   13   280
> 14   14   270
> 15   15   261
> 16   16   251
> 17   17   240
> 18   18   230
> 19   19   220
> 20   20   211
> 21   21   200
> 22   22   191
> 23   23   180
> 24   24   171
> 25   25   160
> 26   26   151
> 27   27   140
> 28   28   130
> 29   29   120
> 30   30   110
> 31   31   100
> 32   3290
> 33   3380
> 34   3470
> 35   3561
> 36   3650
> 37   3741
> 38   3830
> 39   3920
> 40   4010
>
> ## This is basically a transcription of your specification into indexing
> logic
>
> dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
> sampleNo==0],10,rep=FALSE)] <- 2)
>
> ##yielding
> > dat
>
>var1 var2 sampleNo
> 1 1   400
> 2 2   391
> 3 3   380
> 4 4   372
> 5 5   360
> 6 6   351
> 7 7   340
> 8 8   332
> 9 9   320
> 10   10   312
> 11   11   300
> 12   12   290
> 13   13   280
> 14   14   272
> 15   15   261
> 16   16   251
> 17   17   240
> 18   18   232
> 19   19   220
> 20   20   211
> 21   21   200
> 22   22   191
> 23   23   180
> 24   24   171
> 25   25   160
> 26   26   151
> 27   27   140
> 28   28   132
> 29   29   120
> 30   30   112
> 31   31   100
> 32   3292
> 33   3380
> 34   3472
> 35   3561
> 36   3652
> 37   3741
> 38   3830
> 39   3920
> 40   4010
>
>
>
>
>
> dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
> sampleNo==0],10,rep=FALSE)] <- 2)
>
>
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Sep 25, 2017 at 10:27 AM, David Studer  wrote:
>
> > Hello everybody!
> >
> > I have the following problem: I'd like to select a sample from a
> subsample
> > in a dataset. Actually, I don't want to select it, but to create a new
> > variable sampleNo that indicates to which sample (one or two) a case
> > belongs to.
> >
> > Lets suppose I have a dataset containing 40 cases:
> >
> > data <- data.frame(var1=seq(1:40), var2=seq(40,1))
> >
> > The first sample (n=10) I drew like this:
> >
> > data$sampleNo <- 0
> > idx <- sample(seq(1,nrow(data)), size=10, replace=F)
> > data[idx,]$sampleNo <- 1
> >
> > Now, (and here my problems start) I'd like to draw a second sample
> (n=10).
> > But this sample should be drawn from the cases that don't belong to the
> > first sample only. *Additionally, "var1" should be an even number.*
> >
> > So sampleNo should be 0 for cases that were not drawn at all, 1 for cases
> > that belong to the first sample and 2 for cases belonging to the second
> > sample (= sampleNo equals 0 and var1 is even).
> >
> > I was trying to solve it like this:
> >
> > idx2<-data$var1%%2 & data$sampleNo==0
> > sample(data[idx2,], size=10, replace=F)
> >
> > But how can I set sampleNo to 2?
> >
> >
> > Thank you very much for your help!
> >
> > David
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> > posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> [[alternative HTML versi

Re: [R] Sample of a subsample

2017-09-25 Thread Bert Gunter
For personal aesthetic reasons, I changed the name "data" to "dat".

Your code, with a slight modification:

set.seed (1357)  ## for reproducibility
dat <- data.frame(var1=seq(1:40), var2=seq(40,1))
dat$sampleNo <- 0
idx <- sample(seq(1,nrow(dat)), size=10, replace=F)
dat[idx,"sampleNo"] <-1

## yielding
> dat

   var1 var2 sampleNo
1 1   400
2 2   391
3 3   380
4 4   370
5 5   360
6 6   351
7 7   340
8 8   330
9 9   320
10   10   310
11   11   300
12   12   290
13   13   280
14   14   270
15   15   261
16   16   251
17   17   240
18   18   230
19   19   220
20   20   211
21   21   200
22   22   191
23   23   180
24   24   171
25   25   160
26   26   151
27   27   140
28   28   130
29   29   120
30   30   110
31   31   100
32   3290
33   3380
34   3470
35   3561
36   3650
37   3741
38   3830
39   3920
40   4010

## This is basically a transcription of your specification into indexing
logic

dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
sampleNo==0],10,rep=FALSE)] <- 2)

##yielding
> dat

   var1 var2 sampleNo
1 1   400
2 2   391
3 3   380
4 4   372
5 5   360
6 6   351
7 7   340
8 8   332
9 9   320
10   10   312
11   11   300
12   12   290
13   13   280
14   14   272
15   15   261
16   16   251
17   17   240
18   18   232
19   19   220
20   20   211
21   21   200
22   22   191
23   23   180
24   24   171
25   25   160
26   26   151
27   27   140
28   28   132
29   29   120
30   30   112
31   31   100
32   3292
33   3380
34   3472
35   3561
36   3652
37   3741
38   3830
39   3920
40   4010





dat <- within(dat,sampleNo[sample(var1[(var1%%2 == 0) &
sampleNo==0],10,rep=FALSE)] <- 2)




Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 10:27 AM, David Studer  wrote:

> Hello everybody!
>
> I have the following problem: I'd like to select a sample from a subsample
> in a dataset. Actually, I don't want to select it, but to create a new
> variable sampleNo that indicates to which sample (one or two) a case
> belongs to.
>
> Lets suppose I have a dataset containing 40 cases:
>
> data <- data.frame(var1=seq(1:40), var2=seq(40,1))
>
> The first sample (n=10) I drew like this:
>
> data$sampleNo <- 0
> idx <- sample(seq(1,nrow(data)), size=10, replace=F)
> data[idx,]$sampleNo <- 1
>
> Now, (and here my problems start) I'd like to draw a second sample (n=10).
> But this sample should be drawn from the cases that don't belong to the
> first sample only. *Additionally, "var1" should be an even number.*
>
> So sampleNo should be 0 for cases that were not drawn at all, 1 for cases
> that belong to the first sample and 2 for cases belonging to the second
> sample (= sampleNo equals 0 and var1 is even).
>
> I was trying to solve it like this:
>
> idx2<-data$var1%%2 & data$sampleNo==0
> sample(data[idx2,], size=10, replace=F)
>
> But how can I set sampleNo to 2?
>
>
> Thank you very much for your help!
>
> David
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Sample of a subsample

2017-09-25 Thread David Studer
Hello everybody!

I have the following problem: I'd like to select a sample from a subsample
in a dataset. Actually, I don't want to select it, but to create a new
variable sampleNo that indicates to which sample (one or two) a case
belongs to.

Lets suppose I have a dataset containing 40 cases:

data <- data.frame(var1=seq(1:40), var2=seq(40,1))

The first sample (n=10) I drew like this:

data$sampleNo <- 0
idx <- sample(seq(1,nrow(data)), size=10, replace=F)
data[idx,]$sampleNo <- 1

Now, (and here my problems start) I'd like to draw a second sample (n=10).
But this sample should be drawn from the cases that don't belong to the
first sample only. *Additionally, "var1" should be an even number.*

So sampleNo should be 0 for cases that were not drawn at all, 1 for cases
that belong to the first sample and 2 for cases belonging to the second
sample (= sampleNo equals 0 and var1 is even).

I was trying to solve it like this:

idx2<-data$var1%%2 & data$sampleNo==0
sample(data[idx2,], size=10, replace=F)

But how can I set sampleNo to 2?


Thank you very much for your help!

David

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to propose changes to R documentation

2017-09-25 Thread Bert Gunter
1. Familiarize yourself with CRAN and the R homeage:
https://www.r-project.org/

2. https://www.r-project.org/bugs.html


Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 7:54 AM, Dibyadeep Paul  wrote:

> Hi all,
>
> I noticed that there was some confusion regarding a few statements in the R
> documentation. There are multiple questions on Stackoverflow regarding
> this. So I thought it may be helpful for other new users to add a small
> example to clarify the statements.
>
> I am wondering how I can suggest these changes to the R manual? Is there a
> github like interface to R/R manual?
>
> --
> Thanks
>
> Dr. Dibyadeep Paul
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Random Variable Generation

2017-09-25 Thread David L Carlson
Once you have assigned the variable, it does not change unless you change it. 
If you want to draw random numbers repeatedly, put the code into a function:

rnd <- function() {.35 * (runif(1, min=.81, max=1.03) + runif(1, min=1.06, 
max=1.17) + runif(1, min=-.26, max=1.38)) + 
   .30 * (runif(1, min=.36, max=.98) + runif(1, min=.76, max=.93) + runif(1, 
min=.52, max=1.03)) + 
   .20 * (runif(1, min=.36, max=.75) + runif(1, min=.1, max=.67) + runif(1, 
min=.9, max=.96)) + 
   .15 * (runif(1, min=.03, max=.20) + runif(1, min=.27, max=.51) + runif(1, 
min=.49, max=.55)) + 
   .40 * (runif(1, min=.33, max=.39) + runif(1, min=.84, max=1.35)) + 
   .35 * (runif(1, min=.16, max=.58) + runif(1, min=.05, max=1.29)) + 
   .25 * (runif(1, min=.21, max=.52) + runif(1, min=.20, max=.68)) + 
   .50 * (runif(1, min=1.26, max=1.38))
}

Now every time you access the function, you will get a new random number:

> rnd()
[1] 4.036111
> rnd()
[1] 3.88048
> rnd()
[1] 3.984268
> rnd()
[1] 3.808441
> rnd()
[1] 4.219925


David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77843-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Grant 
Beanblossom
Sent: Monday, September 25, 2017 9:21 AM
To: r-help@r-project.org
Subject: [R] Random Variable Generation

I am attempting to write a code that will generate a win probability for a 
hockey team. To do this, I have a code built that will generate a number of 
random variables between two standard deviations, and then weight them and add 
them together. However, when I attempt to assign this code to a variable, any 
time I use the variable, it will always give me the same numbers instead of 
being random every time. Is there a way I can do this so that it is random 
every time?


Here is the code I am currently using: .35*(runif(1, min=.81, 
max=1.03)+runif(1, min=1.06, max=1.17)+runif(1, min=-.26, 
max=1.38))+.3*(runif(1, min=.36, max=.98)+runif(1, min=.76, max=.93)+runif(1, 
min=.52, max=1.03))+.2*(runif(1, min=.36, max=.75)+runif(1, min=.1, 
max=.67)+runif(1, min=.9, max=.96))+.15*(runif(1, min=.03, max=.2)+runif(1, 
min=.27, max=.51)+runif(1, min=.49, max=.55))+.4*(runif(1, min=.33, 
max=.39)+runif(1, min=.84, max=1.35))+.35*(runif(1, min=.16, max=.58)+runif(1, 
min=.05, max=1.29))+.25*(runif(1, min=.21, max=.52)+runif(1, min=.20, 
max=.68))+.5*(runif(1, min=1.26, max=1.38)).


The reason I want to assign it to a variable is because I want to run this code 
1000 times and then get a mean value for it, which I believe might be easier if 
there's a variable assigned to it. However, if there is an easier way to do 
that, that could work as well.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] build a SpatialLines object from a list

2017-09-25 Thread Eric Berger
Hi Ashraf,
It is not obvious to me what your structures are but one problem in your
function is the assignment tt1 <- SpatialLines(list(tt[[i]])).

This will set tt1 to just have one item.

Consider the following

test.func <- function(x) {
tt1 <- list()
for ( i in ... )  {
   ...
   tt1[[i]] <- SpatialLines(tt[[i]])
}
return(tt1)
}

HTH,
Eric


On Mon, Sep 25, 2017 at 3:40 PM, Ashraf Afana via R-help <
r-help@r-project.org> wrote:

> Hi all,I'm trying to build a SpatialLines object from a list that contains
> 124 river segments. Each segment in the list contains the x,y coordinates.
> I'm using the following code to create the SpatialLines object, but it just
> retrieves one segment. Any suggestions?
>
> test.func = function(x){
>  for (i in 1:length(x)) {tt[[i]] <- x[i]; tt[[i]]  =
> Line(tt[[i]]); tt[[i]]  = Lines(list(tt[[i]] ), 'i')tt1 =
> SpatialLines(list(tt[[i]]))   }return(tt1)  }
> Ashraf,
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Random Variable Generation

2017-09-25 Thread Grant Beanblossom
I am attempting to write a code that will generate a win probability for a 
hockey team. To do this, I have a code built that will generate a number of 
random variables between two standard deviations, and then weight them and add 
them together. However, when I attempt to assign this code to a variable, any 
time I use the variable, it will always give me the same numbers instead of 
being random every time. Is there a way I can do this so that it is random 
every time?


Here is the code I am currently using: .35*(runif(1, min=.81, 
max=1.03)+runif(1, min=1.06, max=1.17)+runif(1, min=-.26, 
max=1.38))+.3*(runif(1, min=.36, max=.98)+runif(1, min=.76, max=.93)+runif(1, 
min=.52, max=1.03))+.2*(runif(1, min=.36, max=.75)+runif(1, min=.1, 
max=.67)+runif(1, min=.9, max=.96))+.15*(runif(1, min=.03, max=.2)+runif(1, 
min=.27, max=.51)+runif(1, min=.49, max=.55))+.4*(runif(1, min=.33, 
max=.39)+runif(1, min=.84, max=1.35))+.35*(runif(1, min=.16, max=.58)+runif(1, 
min=.05, max=1.29))+.25*(runif(1, min=.21, max=.52)+runif(1, min=.20, 
max=.68))+.5*(runif(1, min=1.26, max=1.38)).


The reason I want to assign it to a variable is because I want to run this code 
1000 times and then get a mean value for it, which I believe might be easier if 
there's a variable assigned to it. However, if there is an easier way to do 
that, that could work as well.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to propose changes to R documentation

2017-09-25 Thread Dibyadeep Paul
Hi all,

I noticed that there was some confusion regarding a few statements in the R
documentation. There are multiple questions on Stackoverflow regarding
this. So I thought it may be helpful for other new users to add a small
example to clarify the statements.

I am wondering how I can suggest these changes to the R manual? Is there a
github like interface to R/R manual?

-- 
Thanks

Dr. Dibyadeep Paul

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] build a SpatialLines object from a list

2017-09-25 Thread Ashraf Afana via R-help
Hi all,I'm trying to build a SpatialLines object from a list that contains 124 
river segments. Each segment in the list contains the x,y coordinates. I'm 
using the following code to create the SpatialLines object, but it just 
retrieves one segment. Any suggestions?

test.func = function(x){
     for (i in 1:length(x)) {    tt[[i]] <- x[i]; tt[[i]]  = Line(tt[[i]]); 
tt[[i]]  = Lines(list(tt[[i]] ), 'i')    tt1 = SpatialLines(list(tt[[i]]))  
         }return(tt1)  }
Ashraf,
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Subset

2017-09-25 Thread Bert Gunter
 You realize, do you not, that in fact there are no numbers in your "list"
(actually a vector).

It looks like you would do well to spend some time with an R tutorial or
two before posting further to this list. We can help, but cannot substitute
for the basic knowledge that you would gain from doing this.

Cheers,

Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Mon, Sep 25, 2017 at 4:30 AM, Shane Carey  wrote:

> Hi,
>
> Lets say this was a dataframe where I had two columns
>
> a <- c("<0.1", NA, 0.3, 5, "Nil")
> b <- c("<0.1", 1, 0.3, 5, "Nil")
>
> And I just want to remove the rows from the dataframe where there were NAs
> in the b column, what is the syntax for doing that?
>
> Thanks in advance
>
> On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey  wrote:
>
> > Super,
> >
> > Thanks
> >
> > On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe 
> > wrote:
> >
> >> > a <- c("<0.1", NA, 0.3, 5, "Nil")
> >> > a
> >> [1] "<0.1" NA "0.3"  "5""Nil"
> >>
> >> > b <- as.numeric(a)
> >> Warning message:
> >> NAs introduced by coercion
> >> > b
> >> [1]  NA  NA 0.3 5.0  NA
> >>
> >> > b[! is.na(b)]
> >> [1] 0.3 5.0
> >>
> >>
> >> B.
> >>
> >>
> >> > On Sep 22, 2017, at 11:48 AM, Shane Carey 
> wrote:
> >> >
> >> > Hi,
> >> >
> >> > How do I extract just numbers from the following list:
> >> >
> >> > a=c("<0.1",NA,0.3,5,Nil)
> >> >
> >> > so I want to obtain: 0.3 and 5 from the above list
> >> >
> >> > Thanks
> >> >
> >> >
> >> > --
> >> > Le gach dea ghui,
> >> > *Shane Carey*
> >> > *GIS and Data Solutions Consultant*
> >> >
> >> >   [[alternative HTML version deleted]]
> >> >
> >> > __
> >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide http://www.R-project.org/posti
> >> ng-guide.html
> >> > and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >
> >
> > --
> > Le gach dea ghui,
> > *Shane Carey*
> > *GIS and Data Solutions Consultant*
> >
>
>
>
> --
> Le gach dea ghui,
> *Shane Carey*
> *GIS and Data Solutions Consultant*
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subset

2017-09-25 Thread Shane Carey
Super, thanks Boris. Top notch :-)

On Mon, Sep 25, 2017 at 1:05 PM, Boris Steipe 
wrote:

> Always via logical expressions. In this case you can use the logical
> expression
>
> myDF$b  != "0"
>
> to give you a vector of TRUE/FALSE
>
>
>
> B.
>
>
> > On Sep 25, 2017, at 8:00 AM, Shane Carey  wrote:
> >
> > This is super, really helpfull. Sorry, one final question, lets say I
> wanted to remove 0's rather than NAs , what would it be?
> >
> > Thanks
> >
> > On Mon, Sep 25, 2017 at 12:41 PM, Boris Steipe 
> wrote:
> > myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
> >b = c("<0.1", 1, 0.3, 5, "Nil"),
> >stringsAsFactors = FALSE)
> >
> > # you can subset the b-column in several ways
> >
> > myDF[ , 2]
> > myDF[ , "b"]
> > myDF$b
> >
> > # using the column, you make a logical vector
> > ! is.na(as.numeric(myDF$b))
> >
> >
> > # This can be used to select the rows you want
> >
> > myDF[! is.na(as.numeric(myDF$b)), ]
> >
> >
> >
> > B.
> >
> >
> > > On Sep 25, 2017, at 7:30 AM, Shane Carey  wrote:
> > >
> > > Hi,
> > >
> > > Lets say this was a dataframe where I had two columns
> > >
> > > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > > b <- c("<0.1", 1, 0.3, 5, "Nil")
> > >
> > > And I just want to remove the rows from the dataframe where there were
> NAs in the b column, what is the syntax for doing that?
> > >
> > > Thanks in advance
> > >
> > > On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey 
> wrote:
> > > Super,
> > >
> > > Thanks
> > >
> > > On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe <
> boris.ste...@utoronto.ca> wrote:
> > > > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > > > a
> > > [1] "<0.1" NA "0.3"  "5""Nil"
> > >
> > > > b <- as.numeric(a)
> > > Warning message:
> > > NAs introduced by coercion
> > > > b
> > > [1]  NA  NA 0.3 5.0  NA
> > >
> > > > b[! is.na(b)]
> > > [1] 0.3 5.0
> > >
> > >
> > > B.
> > >
> > >
> > > > On Sep 22, 2017, at 11:48 AM, Shane Carey 
> wrote:
> > > >
> > > > Hi,
> > > >
> > > > How do I extract just numbers from the following list:
> > > >
> > > > a=c("<0.1",NA,0.3,5,Nil)
> > > >
> > > > so I want to obtain: 0.3 and 5 from the above list
> > > >
> > > > Thanks
> > > >
> > > >
> > > > --
> > > > Le gach dea ghui,
> > > > *Shane Carey*
> > > > *GIS and Data Solutions Consultant*
> > > >
> > > >   [[alternative HTML version deleted]]
> > > >
> > > > __
> > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > > > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > >
> > >
> > > --
> > > Le gach dea ghui,
> > > Shane Carey
> > > GIS and Data Solutions Consultant
> > >
> > >
> > >
> > > --
> > > Le gach dea ghui,
> > > Shane Carey
> > > GIS and Data Solutions Consultant
> >
> >
> >
> >
> > --
> > Le gach dea ghui,
> > Shane Carey
> > GIS and Data Solutions Consultant
>
>


-- 
Le gach dea ghui,
*Shane Carey*
*GIS and Data Solutions Consultant*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subset

2017-09-25 Thread Boris Steipe
Always via logical expressions. In this case you can use the logical expression

myDF$b  != "0"

to give you a vector of TRUE/FALSE 



B.


> On Sep 25, 2017, at 8:00 AM, Shane Carey  wrote:
> 
> This is super, really helpfull. Sorry, one final question, lets say I wanted 
> to remove 0's rather than NAs , what would it be?
> 
> Thanks
> 
> On Mon, Sep 25, 2017 at 12:41 PM, Boris Steipe  
> wrote:
> myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
>b = c("<0.1", 1, 0.3, 5, "Nil"),
>stringsAsFactors = FALSE)
> 
> # you can subset the b-column in several ways
> 
> myDF[ , 2]
> myDF[ , "b"]
> myDF$b
> 
> # using the column, you make a logical vector
> ! is.na(as.numeric(myDF$b))
> 
> 
> # This can be used to select the rows you want
> 
> myDF[! is.na(as.numeric(myDF$b)), ]
> 
> 
> 
> B.
> 
> 
> > On Sep 25, 2017, at 7:30 AM, Shane Carey  wrote:
> >
> > Hi,
> >
> > Lets say this was a dataframe where I had two columns
> >
> > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > b <- c("<0.1", 1, 0.3, 5, "Nil")
> >
> > And I just want to remove the rows from the dataframe where there were NAs 
> > in the b column, what is the syntax for doing that?
> >
> > Thanks in advance
> >
> > On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey  wrote:
> > Super,
> >
> > Thanks
> >
> > On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe  
> > wrote:
> > > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > > a
> > [1] "<0.1" NA "0.3"  "5""Nil"
> >
> > > b <- as.numeric(a)
> > Warning message:
> > NAs introduced by coercion
> > > b
> > [1]  NA  NA 0.3 5.0  NA
> >
> > > b[! is.na(b)]
> > [1] 0.3 5.0
> >
> >
> > B.
> >
> >
> > > On Sep 22, 2017, at 11:48 AM, Shane Carey  wrote:
> > >
> > > Hi,
> > >
> > > How do I extract just numbers from the following list:
> > >
> > > a=c("<0.1",NA,0.3,5,Nil)
> > >
> > > so I want to obtain: 0.3 and 5 from the above list
> > >
> > > Thanks
> > >
> > >
> > > --
> > > Le gach dea ghui,
> > > *Shane Carey*
> > > *GIS and Data Solutions Consultant*
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide 
> > > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > --
> > Le gach dea ghui,
> > Shane Carey
> > GIS and Data Solutions Consultant
> >
> >
> >
> > --
> > Le gach dea ghui,
> > Shane Carey
> > GIS and Data Solutions Consultant
> 
> 
> 
> 
> -- 
> Le gach dea ghui,
> Shane Carey
> GIS and Data Solutions Consultant

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subset

2017-09-25 Thread Shane Carey
This is super, really helpfull. Sorry, one final question, lets say I
wanted to remove 0's rather than NAs , what would it be?

Thanks

On Mon, Sep 25, 2017 at 12:41 PM, Boris Steipe 
wrote:

> myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
>b = c("<0.1", 1, 0.3, 5, "Nil"),
>stringsAsFactors = FALSE)
>
> # you can subset the b-column in several ways
>
> myDF[ , 2]
> myDF[ , "b"]
> myDF$b
>
> # using the column, you make a logical vector
> ! is.na(as.numeric(myDF$b))
>
>
> # This can be used to select the rows you want
>
> myDF[! is.na(as.numeric(myDF$b)), ]
>
>
>
> B.
>
>
> > On Sep 25, 2017, at 7:30 AM, Shane Carey  wrote:
> >
> > Hi,
> >
> > Lets say this was a dataframe where I had two columns
> >
> > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > b <- c("<0.1", 1, 0.3, 5, "Nil")
> >
> > And I just want to remove the rows from the dataframe where there were
> NAs in the b column, what is the syntax for doing that?
> >
> > Thanks in advance
> >
> > On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey 
> wrote:
> > Super,
> >
> > Thanks
> >
> > On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe 
> wrote:
> > > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > > a
> > [1] "<0.1" NA "0.3"  "5""Nil"
> >
> > > b <- as.numeric(a)
> > Warning message:
> > NAs introduced by coercion
> > > b
> > [1]  NA  NA 0.3 5.0  NA
> >
> > > b[! is.na(b)]
> > [1] 0.3 5.0
> >
> >
> > B.
> >
> >
> > > On Sep 22, 2017, at 11:48 AM, Shane Carey  wrote:
> > >
> > > Hi,
> > >
> > > How do I extract just numbers from the following list:
> > >
> > > a=c("<0.1",NA,0.3,5,Nil)
> > >
> > > so I want to obtain: 0.3 and 5 from the above list
> > >
> > > Thanks
> > >
> > >
> > > --
> > > Le gach dea ghui,
> > > *Shane Carey*
> > > *GIS and Data Solutions Consultant*
> > >
> > >   [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> >
> > --
> > Le gach dea ghui,
> > Shane Carey
> > GIS and Data Solutions Consultant
> >
> >
> >
> > --
> > Le gach dea ghui,
> > Shane Carey
> > GIS and Data Solutions Consultant
>
>


-- 
Le gach dea ghui,
*Shane Carey*
*GIS and Data Solutions Consultant*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subset

2017-09-25 Thread Boris Steipe
myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
   b = c("<0.1", 1, 0.3, 5, "Nil"),
   stringsAsFactors = FALSE)

# you can subset the b-column in several ways

myDF[ , 2]
myDF[ , "b"]
myDF$b

# using the column, you make a logical vector
! is.na(as.numeric(myDF$b))


# This can be used to select the rows you want

myDF[! is.na(as.numeric(myDF$b)), ]



B.


> On Sep 25, 2017, at 7:30 AM, Shane Carey  wrote:
> 
> Hi,
> 
> Lets say this was a dataframe where I had two columns
> 
> a <- c("<0.1", NA, 0.3, 5, "Nil")
> b <- c("<0.1", 1, 0.3, 5, "Nil")
> 
> And I just want to remove the rows from the dataframe where there were NAs in 
> the b column, what is the syntax for doing that?
> 
> Thanks in advance
> 
> On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey  wrote:
> Super,
> 
> Thanks
> 
> On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe  
> wrote:
> > a <- c("<0.1", NA, 0.3, 5, "Nil")
> > a
> [1] "<0.1" NA "0.3"  "5""Nil"
> 
> > b <- as.numeric(a)
> Warning message:
> NAs introduced by coercion
> > b
> [1]  NA  NA 0.3 5.0  NA
> 
> > b[! is.na(b)]
> [1] 0.3 5.0
> 
> 
> B.
> 
> 
> > On Sep 22, 2017, at 11:48 AM, Shane Carey  wrote:
> >
> > Hi,
> >
> > How do I extract just numbers from the following list:
> >
> > a=c("<0.1",NA,0.3,5,Nil)
> >
> > so I want to obtain: 0.3 and 5 from the above list
> >
> > Thanks
> >
> >
> > --
> > Le gach dea ghui,
> > *Shane Carey*
> > *GIS and Data Solutions Consultant*
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> 
> 
> 
> -- 
> Le gach dea ghui,
> Shane Carey
> GIS and Data Solutions Consultant
> 
> 
> 
> -- 
> Le gach dea ghui,
> Shane Carey
> GIS and Data Solutions Consultant

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Subset

2017-09-25 Thread Shane Carey
Hi,

Lets say this was a dataframe where I had two columns

a <- c("<0.1", NA, 0.3, 5, "Nil")
b <- c("<0.1", 1, 0.3, 5, "Nil")

And I just want to remove the rows from the dataframe where there were NAs
in the b column, what is the syntax for doing that?

Thanks in advance

On Fri, Sep 22, 2017 at 5:04 PM, Shane Carey  wrote:

> Super,
>
> Thanks
>
> On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe 
> wrote:
>
>> > a <- c("<0.1", NA, 0.3, 5, "Nil")
>> > a
>> [1] "<0.1" NA "0.3"  "5""Nil"
>>
>> > b <- as.numeric(a)
>> Warning message:
>> NAs introduced by coercion
>> > b
>> [1]  NA  NA 0.3 5.0  NA
>>
>> > b[! is.na(b)]
>> [1] 0.3 5.0
>>
>>
>> B.
>>
>>
>> > On Sep 22, 2017, at 11:48 AM, Shane Carey  wrote:
>> >
>> > Hi,
>> >
>> > How do I extract just numbers from the following list:
>> >
>> > a=c("<0.1",NA,0.3,5,Nil)
>> >
>> > so I want to obtain: 0.3 and 5 from the above list
>> >
>> > Thanks
>> >
>> >
>> > --
>> > Le gach dea ghui,
>> > *Shane Carey*
>> > *GIS and Data Solutions Consultant*
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
> --
> Le gach dea ghui,
> *Shane Carey*
> *GIS and Data Solutions Consultant*
>



-- 
Le gach dea ghui,
*Shane Carey*
*GIS and Data Solutions Consultant*

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Shift the normal curve to the top or near to the top of the histogram

2017-09-25 Thread Rui Barradas

Hello,

Try using hist argument 'prob = TRUE' or, which is equivalent, 'freq = 
FALSE'.


hist(..., prob = TRUE)   # or hist(..., freq = FALSE)

This is because like this you will have a density, comparable to a 
parametric density. Note that the peak of the normal will be outside the 
plot area so you will have to adjust the plot area dimensions. In this 
case I've set 'ylim = c(0, 0.35)'.



hist(Lizard.tail.lengths, main = "Normal Probability Plot of Lizard Tail
Lengths", ylim = c(0, 0.35), prob = TRUE)

curve(dnorm(x ,mean=mean(Lizard.tail.lengths),sd=sd(Lizard.tail.lengths)),
add=TRUE, col=2, lwd = 2)


Hope this helps,

Rui Barradas

Em 25-09-2017 00:35, AbouEl-Makarim Aboueissa escreveu:

Dear All:

One more thing.

I want to add the normal curve to the histogram. Is there away to stretch
the peak of the curve to the top of the histogram or at least near to the
top of the histogram.

Please see the code below.


Lizard.tail.lengths <- c(6.2, 6.6, 7.1, 7.4, 7.6, 7.9, 8, 8.3, 8.4, 8.5,
8.6,8.8, 8.8, 9.1, 9.2, 9.4, 9.4, 9.7, 9.9, 10.2, 10.4, 10.8,11.3, 11.9)

x<-seq(5,12, 0.001)

hist(Lizard.tail.lengths, main = "Normal Probability Plot of Lizard Tail
Lengths")

curve(dnorm(x ,mean=mean(Lizard.tail.lengths),sd=sd(Lizard.tail.lengths)),
add=TRUE, col=2, lwd = 2)



with many thanks
abou
__
AbouEl-Makarim Aboueissa, PhD
Professor of Statistics
Department of Mathematics and Statistics
University of Southern Maine

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.