[R] Trouble in creating a list

Gang Chen gangchen at mail.nih.gov
Wed Nov 7 19:21:02 CET 2007


I want to create a list based on the information from a data.frame,  
Model. So I tried the following:

MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))

but it failed with an error:

Error: unexpected '=' in "list(colnames(Model)[2] ="

I have the following problems with this command line:

(1) I wanted to use colnames(Model)[2] as a tag for the list:

 > colnames(Model)[2]
[1] "gender"

but it is not working as I intended. How to make colnames(Model)[2] a  
legitimate tag?

(2) Model$gender is a column in the data.frame. However Model$ 
(colnames(Model)[2]) seems not recognizable in the command line. How  
to correct this?

(3) How to add more tagged items to an existing list? cbind or rbind?

Thanks in advance,
Gang



More information about the R-help mailing list