[R] List indexing question
David Perlman
dperlman at wisc.edu
Tue May 22 02:07:41 CEST 2012
Consider the following:
> x<-list(c(1,2,3),c(4,5,6))
> x[1]
[[1]]
[1] 1 2 3
> x[2]
[[1]]
[1] 4 5 6
So far that all seems reasonable. But now there's a problem. I'm used to python, where I would say x[2][1] and get the value 4. But I can't figure out how to do that in R.
> x[2][1]
[[1]]
[1] 4 5 6
> x[2,1]
Error in x[2, 1] : incorrect number of dimensions
I have no idea why x[2][1] returns the same thing as x[2]; that makes no sense to me at all.
What is the proper syntax for what I'm trying to do?
Thanks!
-dave----------------------------------------------------------------------
A neuroscientist is at the video arcade, when someone makes him a $1000 bet
on Pac-Man. He smiles, gets out his screwdriver and takes apart the Pac-Man
game. Everyone says "What are you doing?" The neuroscientist says "Well,
since we all know that Pac-Man is based on electric signals traveling
through these circuits, obviously I can understand it better than the other
guy by going straight to the source!"
More information about the R-help
mailing list