Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-20 Thread Martin Møller Skarbiniks Pedersen
On Sun, 20 Dec 2020 at 06:22, Richard O'Keefe wrote: > More accurately, in x[i] where x and i are simple vectors, > i may be a mix of positive integers and zeros > where the zeros contribute nothing to the result > Yes, index 0 doesn't get an error or a warning. I think it should. Eg. (v <- 1

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-20 Thread Jeff Newmiller
I've never mastered using negative indexes with my fingers, though... On December 19, 2020 11:32:46 PM PST, Jim Lemon wrote: >It does remind me of counting on one's fingers, though. > >Jim > >On Sun, Dec 20, 2020 at 4:38 PM Bert Gunter >wrote: >> >But c(x[-1], x[1]) is, which is not so terrible

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Jim Lemon
It does remind me of counting on one's fingers, though. Jim On Sun, Dec 20, 2020 at 4:38 PM Bert Gunter wrote: > But c(x[-1], x[1]) is, which is not so terrible, after all... __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https:

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Bert Gunter
Inline... On Sat, Dec 19, 2020 at 9:22 PM Richard O'Keefe wrote: > More accurately, in x[i] where x and i are simple vectors, > i may be a mix of positive integers and zeros > where the zeros contribute nothing to the result > or it may be a MIX of negative integers and zeros > where the ze

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Richard O'Keefe
More accurately, in x[i] where x and i are simple vectors, i may be a mix of positive integers and zeros where the zeros contribute nothing to the result or it may be a MIX of negative integers and zeros where the zeros contribute nothing to the result and -k means "do not include element k".

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Chao Liu
Jim and Bert, Thank you for your help. It was an indexing problem. I was able to solve it by changing the split line to: clusters <- split(seq_len(nrow(dd)), dd$cluster). Thank you. Best, Chao On Sat, Dec 19, 2020 at 4:19 PM Jim Lemon wrote: > Hi Chao, > You have discovered one of the surpri

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Jim Lemon
Hi Chao, You have discovered one of the surprising things about the extraction operator "[". It expects to get an object consisting of integers (like 1,2,3,...) or logical values (TRUE,FALSE or 0,1). As you have passed the _values_ of your cluster, it can't deal with the negative numbers as they do

Re: [R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Bert Gunter
1. Thanks for the example. 2. Good opportunity to learn (more) about debugging in R. See ?debug or ?browser() 3. Hint: what do you think ... unlist(clusters[... gives? (you are using it as an index for subscripting dd) Cheers, Bert Bert Gunter "The trouble with having an open mind is that peop

[R] Problem in cluster sampling: 'mixed with negative subscripts'

2020-12-19 Thread Chao Liu
Hi, I was trying to do a cluster sampling but came across this error: Error in xj[i] : only 0's may be mixed with negative subscripts. What is the cause and how to get around? Thank you for your help! Here is the code: #simulate some data y <- rnorm(20) x <- rnorm(20) z <- rep(1:5, 4) w <- rep(1