[R] Accessing variable's name as an attribute?
Rob Forsyth
rob.forsyth at newcastle.ac.uk
Thu Mar 15 16:40:53 CET 2012
Sorry - I suspect this is a very basic query.
I have a data frame structured "flat" (i.e. separate observations for a given subject ID on separate lines). Using the nlme library I create a groupedData object suitable for further analysis thus:
dataset <- groupedData(VARIABLE ~ TIME|ID, data=sfa)
The dataset has a large number of VARIABLES of interest so I want to make use of loops where possible to build groupedData objects from each of the relevant columns along the lines of:
sfa <- na.omit(read.csv("SFAFinalData.csv", header = TRUE))
factorsList <- colnames(sfa)
noFactors <- length(factorsList)
for (i in seq(4,noFactors)) {
columnName <- factorsList[i]
dataset <- groupedData(sfa[,columnName] ~ TIME|ID, data=sfa, labels = list("Weeks post injury", columnName))
}
Of course at present this simply results in sequential overwriting of dataset with the latest groupedData object. What I want to do with each iteration of the loop I want to create another uniquely named groupedData object - I just don't know how to assign a unique variable name.
names(dataset) is not the right attribute (this alters the names of the internal column names) - can I set a variable name attribute directly?
thanks
Rob
More information about the R-help
mailing list