[R] elegant solution to transform vector into percentages?
reid_huntsinger at merck.com
Tue Jul 26 21:57:47 CEST 2005
hist() or cut() followed by tabulate() would probably be the ingredients
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
jhainm at fas.harvard.edu
Sent: Tuesday, July 26, 2005 3:49 PM
To: r-help at stat.math.ethz.ch
Subject: [R] elegant solution to transform vector into percentages?
I am looking for an elegant way to transform a vector into percentages of
that meet certain criteria.
# now I want to get the precentages of values
# that fall into the categories <=M , >M & <=N , >N
N <- 1.2
# In my real example I have many more of these cutoff-points
# What I did is:
out <- matrix(NA,1,3)
out[1,1] <- ( (sum(store<=M )) /length(store) )*100
out[1,2] <- ( (sum(store> M & store<= N )) /length(store) )*100
out[1,3] <- ( (sum(store> N )) /length(store) )*100
colnames(out)<-c("percent<=M","percent>M & <=N","percent>N")
But this gets very tedious if I have many cutoff-points. Does anybody know a
more elegant way to do this task?
Thanks so much.
R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!
More information about the R-help