[R] averaging rows based on string¿?
alfredo
alfredotello at gmail.com
Fri Jul 22 22:00:55 CEST 2011
Hi Folks,
Ran into something I'd really like to do in R simply/elegantly, but my R -
coding skills seem surpassed. This is the thing. Imagine the following data:
labs<-c("abcdef","abcgg","tgthefdk","tgtijuel","tgtnjmoi","gbnt","dlift")
dat<-c(0.5,0.25,1,2,16,0.250,4)
dframe<-data.frame(labs,dat)
I would like to average the values in "dat" according to specific
string/text in the name of their row names described by "labs". For example,
average the values in "dat" if the first three (or more) letters in their
corresponding "labs" are the same. This would give the following vector:
0.375000 6.333333 0.250000 4.000000 # in which 0.375 is the average of
"abcdef" and "abcgg", etc.
I hope I've made myself (kind'a) clear and apologise otherwise. Any ideas?
Thanks for your help!
A
--
View this message in context: http://r.789695.n4.nabble.com/averaging-rows-based-on-string-tp3687689p3687689.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list