Jie TANG
2011-Aug-18 05:36 UTC
[R] can i use a variable to describe the dimension name of a data.frame?
for example: a data.frame data V1 V2 V3 1 2 3 4 5 6 If I want to calculate the V2 I can get data$V2 But now I want to calculate the dimension name and then analysis the data. for example No=3*x ;x=1,2,3,...n anadata=data$VNo How could I do? -- TANG Jie [[alternative HTML version deleted]]
David Winsemius
2011-Aug-18 06:37 UTC
[R] can i use a variable to describe the dimension name of a data.frame?
On Aug 18, 2011, at 1:36 AM, Jie TANG wrote:> for example: > a data.frame > data > V1 V2 V3 > 1 2 3 > 4 5 6 > > If I want to calculate the V2 > I can get data$V2 > But now I want to calculate the dimension name and then analysis the > data. > for example > No=3*x ;x=1,2,3,...n > anadata=data$VNo > How could I do?If you are asking how to access the n-th column then try this: data[[n]] # returns a vector or data[1:5] # returns a dataframe You could also use: vname <- paste("V", 1:5, sep="") data[vname] This does suggest that yoy need to read your introductory material more closely, because this would be covered in an early chapter. -- David Winsemius, MD West Hartford, CT