[R] specifying column names in a vector of characters and the use?
Seth
sjmyers at syr.edu
Mon Jul 19 04:09:53 CEST 2010
Hi,
What I would like to do is have a data.frame with column names and have
these column names stored as strings in another vector. Then I would like
to be able to access the data.fram columns via referencing the vector of
names. The code below shows the last few executions that failed to retrieve
the values for column named X1. Seth
> table.1<-cbind(c(1,2,3,2,2),c(0,9,0,7,9),c(7,5,9,8,8))
> table.1
[,1] [,2] [,3]
[1,] 1 0 7
[2,] 2 9 5
[3,] 3 0 9
[4,] 2 7 8
[5,] 2 9 8
>
> table.1<-data.frame(table.1)
> table.1
X1 X2 X3
1 1 0 7
2 2 9 5
3 3 0 9
4 2 7 8
5 2 9 8
> hold<-c("X1","X2","X3")
> hold
[1] "X1" "X2" "X3"
> table.1$X1
[1] 1 2 3 2 2
> hold[1]
[1] "X1"
> table.1$hold[1] # FROM HERE DOWN ARE MY ATTEMPTS TO ACCESS X1
NULL
> table.1$(hold[1])
Error: unexpected '(' in "table.1$("
> table.1$get(hold[1])
Error: attempt to apply non-function
> table.1$(get(hold[1]))
Error: unexpected '(' in "table.1$("
>
--
View this message in context: http://r.789695.n4.nabble.com/specifying-column-names-in-a-vector-of-characters-and-the-use-tp2293494p2293494.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list