Ista Zahn <izahn <at> psych.rochester.edu> writes: > > Hi, > I think an example would be helpful. I'm not sure what behavior you > are referring to. > > best,
Here is an example: If a data.frame of experimental results is read from an external file, a column of strings, e.g. subject codes, is converted to a factor by default. If I have a second table containing additional data for the subjects (or a big pool of subjects) with subject code as rownames, then sometimes I want to add data looked up from the 2nd table to the data.frame, possibly to use them as additional covariates. The wrong way to do is: df$age <- table2[df$Subject,"age"] This doesn't work as expected because df$Subject is silently converted to a number, which not meaningful for table2 except when the table happens to list the subjects in the order of levels of df$Subject. So only df$age <- table2[levels(df$Subject)[as.numeric(df$Subject)],"age"] or df$age <- table2[as.character(df$Subject),"age"] is expected to work correctly, as is explained in the factor() doc. This has biten me more than once, and it will bite users I am going to evangelize R to, too. ______________________________________________ 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.