r - access column reference to summarise column using dplyr -


i have been trying find way iterate through columns in dataframe using dplyr can perform operations on each column. dont quite understand how reference each column without hardcoding column name.

for example, column means using apply: apply(exampledf,2,function(x){mean(x)})

note reference column x can passed function. there similar missing in dplyr?

the specific task trying (along non-working dplyr code) create new column contains column_mean(column_sd):

library(dplyr) set.seed(42) exampledf<- as.data.frame(matrix(ceiling(runif(16,0,50)), ncol=4)) colnames(exampledf)<-c("c1","c2","c3","c4") row.names(exampledf)<-c("r1","r2","r3","r4") exampledf%>%group_by(exampledf$c1)%>%mutate(meansd=paste(mean()+"("+sd()+")")) 

goal

   c1 c2 c3 c4 meansd r1 46 33 33 47 37.50(15.15) r2 47 26 36 13 25.75(13.30) r3 15 37 23 24 32.00(6.16) r4 42  7 36 48 33.00(17.33) 


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -