r - Convert from lowercase to uppercase all values in all character variables in dataframe -


i have mixed dataframe of character , numeric variables.

city,hs_cd,sl_no,col_01,col_02,col_03 austin,1,2,,46,female austin,1,3,,32,male austin,1,4,,27,male austin,1,5,,20,female austin,2,2,,42,female austin,2,1,,52,male austin,2,3,,25,male austin,2,4,,22,female austin,3,3,,30,female austin,3,1,,65,female 

i want convert lower-case characters in dataframe uppercase. there way in 1 shot without doing repeatedly on each character-variable?

starting following sample data :

df <- data.frame(v1=letters[1:5],v2=1:5,v3=letters[10:14],stringsasfactors=false)    v1 v2 v3 1   1  j 2  b  2  k 3  c  3  l 4  d  4  m 5  e  5  n 

you can use :

data.frame(lapply(df, function(v) {   if (is.character(v)) return(toupper(v))   else return(v) })) 

which gives :

  v1 v2 v3 1   1  j 2  b  2  k 3  c  3  l 4  d  4  m 5  e  5  n 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -