[R] Change case of factor in data frame

Audrey barnett.audrey at gmail.com
Tue Dec 4 00:34:45 CET 2012


> res=names(dat);
> get(res[ind],pos=dat) will retrieve dat$name


There are far less baroque was of doing that (including dat$name and  
dat[["name"]].

Both dat$name and dat[["name"]] require you to know what "name" is. I was
looking for a way to retrieve a data frame column by name without actually
knowing what the data frame column name was. get() seems to do that, but I
am open to other options. 

Thank you for your advice regarding [ vs. [[. Indeed, lower(dat[[ind]]) does
return the desired result. However, it seems that ind can only be a single
integer (or evaluate to TRUE for only 1 column), I guess because "[[" is
returning a vector. 

By "text" I mean anything that was non-numerical: character and factor
classes, in my case. 



--
View this message in context: http://r.789695.n4.nabble.com/Change-case-of-factor-in-data-frame-tp4651696p4651971.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list