Hi, i think that is more easy MyList <- list(levels(Model[,colnames(Model)[2]])) names(MyList) <- colnames(Model)[2]
On 07/11/2007, Gang Chen <[EMAIL PROTECTED]> wrote: > > Hi, > > I really appreciate your help! As I'm still learning basics in R, please > pardon my simple questions. > > It seems > > eval(parse(text=paste("MyList<-list(", colnames(Model)[2], "=", > levels(Model[,colnames(Model)[2]]), ")"))) > > > is almost what I want except the following error: > Error in eval(expr, envir, enclos) : object "M" not found > > Well, I tried > > > parse(text=paste("MyList<-list(", colnames(Model)[2], "=", > levels(Model[,colnames(Model)[2]]), ")")) > expression(MyList<-list( Trust = F ), MyList<-list( Trust = M )) > attr(,"srcfile") > <text> > > > levels(Model[,colnames(Model)[2]]) > [1] "F" "M" > > Is it because we need quotes around F and M for eval the command? If so, > how can I make it work? > > Thanks a million, > Gang > > > > > On Nov 7, 2007, at 2:18 PM, Henrique Dallazuanna wrote: > > Try this: > > 1)eval(parse(text=paste("MyList<-list(", colnames(Model)[2], "=", > Model[,colnames(Model)[2]], ")"))) > > 2)Model[,colnames(Model)[2]] > > 3)MyList[[3]] <- "Teste" > MyList[[4]] <- "Teste1" > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > On 07/11/2007, Gang Chen <[EMAIL PROTECTED]> wrote: > > > > > > 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 > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.