Hello, this is just a point of curiosity with me. I want a sequence of numbers from 64 to 70, omitting the 2nd and 4th numbers. I can do it these ways:> seq(64, 70)[-c(2, 4)][1] 64 66 68 69 70> foo <- 64:70 > foo[-c(2, 4)][1] 64 66 68 69 70 But how come this doesn't work?> 64:70[-c(2, 4)][1] 64 65 66 67 68 69 70 Just wondering. -- Stuart Luppescu -=- slu .at. ccsr.uchicago.edu University of Chicago -=- CCSR ???????? -=- Kernel 2.6.30-gentoo-r5 Cordelia: Hi! You having fun? Angel: Sure. This is, uh... Cordelia: Your idea of hell. Angel: Actually, in hell you tend to know a lot of the people
Order of operations. Since you didn't specify the order you wanted by using parentheses, R chose, and it wasn't what you wanted.> 64:70[-c(2, 4)] # what you said[1] 64 65 66 67 68 69 70> (64:70)[-c(2, 4)] # what you thought you said[1] 64 66 68 69 70> 64:(70[-c(2, 4)]) # what R thought you said[1] 64 65 66 67 68 69 70 Sarah On Fri, Feb 19, 2010 at 4:33 PM, Stuart Luppescu <slu at ccsr.uchicago.edu> wrote:> Hello, this is just a point of curiosity with me. I want a sequence of > numbers from 64 to 70, omitting the 2nd and 4th numbers. I can do it > these ways: > >> seq(64, 70)[-c(2, 4)] > [1] 64 66 68 69 70 > >> foo <- 64:70 >> foo[-c(2, 4)] > [1] 64 66 68 69 70 > > But how come this doesn't work? >> 64:70[-c(2, 4)] > [1] 64 65 66 67 68 69 70 > > Just wondering.-- Sarah Goslee http://www.functionaldiversity.org
See ?Syntax noting from the list of operators there that : is of lower precedence than [. On Fri, Feb 19, 2010 at 4:33 PM, Stuart Luppescu <slu at ccsr.uchicago.edu> wrote:> Hello, this is just a point of curiosity with me. I want a sequence of > numbers from 64 to 70, omitting the 2nd and 4th numbers. I can do it > these ways: > >> seq(64, 70)[-c(2, 4)] > [1] 64 66 68 69 70 > >> foo <- 64:70 >> foo[-c(2, 4)] > [1] 64 66 68 69 70 > > But how come this doesn't work? >> 64:70[-c(2, 4)] > [1] 64 65 66 67 68 69 70 > > Just wondering. > -- > Stuart Luppescu -=- slu .at. ccsr.uchicago.edu > University of Chicago -=- CCSR > ???????? -=- Kernel 2.6.30-gentoo-r5 > Cordelia: Hi! You having fun? Angel: Sure. This is, > uh... Cordelia: Your idea of hell. Angel: > Actually, in hell you tend to know a lot of the > people > > ______________________________________________ > R-help at r-project.org mailing list > 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. >
On 02/20/2010 08:33 AM, Stuart Luppescu wrote:> Hello, this is just a point of curiosity with me. I want a sequence of > numbers from 64 to 70, omitting the 2nd and 4th numbers. I can do it > these ways: > >> seq(64, 70)[-c(2, 4)] > [1] 64 66 68 69 70 > >> foo<- 64:70 >> foo[-c(2, 4)] > [1] 64 66 68 69 70 > > But how come this doesn't work? >> 64:70[-c(2, 4)] > [1] 64 65 66 67 68 69 70 > > Just wondering.Ah, but it does work! (64:70)[-c(2,4)] [1] 64 66 68 69 70 Jim