[R] Accessing variable's name as an attribute?
    Rui Barradas 
    rui1174 at sapo.pt
       
    Thu Mar 15 18:47:59 CET 2012
    
    
  
Hello,
>
> 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. 
> 
The best way should be to create a list of groupedData objects. Along the
lines of
library(nlme)
n <- 100
df1 <- data.frame(A=sample(LETTERS[1:5], n, T),
		B=sample(letters[1:5], n, T),
		C1=rnorm(n),
		C2=rnorm(n))
factorsList <- colnames(df1)
# First initialize to object of class 'list'
dataset <- list()
for(i in 3:4){
	# If you want another name for each groupedData object:
	# grname <- paste("gr", factorsList[i], sep="")
	grname <- factorsList[i]
	dataset[[ grname ]] <- groupedData(df1[, i] ~ A | B, data=df1)
}
str(dataset)
# Now use their unique names with the operator '$' or with '[['
dataset$C1
Grouped Data: df1[, i] ~ A | B
    A B           C1           C2
1   C e  0.001311565  2.237548657
2   B d  1.393674594  0.507935464
3   C c -0.821700986 -2.118189680
4   C d  0.314210639 -0.771531899
[... etc ...]
99  C e -0.435389239  1.024320656
100 D e  0.919110919  0.667429797
Hope this helps,
Rui Barradas
--
View this message in context: http://r.789695.n4.nabble.com/Accessing-variable-s-name-as-an-attribute-tp4475564p4475793.html
Sent from the R help mailing list archive at Nabble.com.
    
    
More information about the R-help
mailing list