Displaying 1 result from an estimated 1 matches for "change_case".
Did you mean:
change_base
2012 Dec 02
2
Change case of factor in data frame
...as.character during the function call does not work (e.g.
tolower(as.character(dat[1]))).
So, I would loop over the column names, but I can not figure out how to
generically call them:
tst=names(dat);
dat$(tst[1]) returns an error
dat[tst[1]] returns class data.frame again
Thank you in advance!
change_case<-function(dat,wcase){
# change case
res=sapply(dat,class); # get classes
ind<-res=='character';
dat[ind]<-switch(wcase,
'lower'=tolower(dat[ind]),
'upper'=toupper(dat[ind])
)
rm(ind);
ind<-res=='factor';...