[R] Request help writing a function
ggrothendieck at myway.com
Sun Jun 6 06:51:55 CEST 2004
I think you need to give an example of input and output to clarify your
question but in case this helps, if x is a numeric vector then
mean(x==2, na.rm=T) gives the proportion of 2s among the non-NAs in x.
Greg Blevins <gblevins <at> mn.rr.com> writes:
: I have been wrestling with this function for quite a while, and am not
: 1) I want to apply a function to the following columns of a dataframe:
: myfunction. <- apply(ph5028[,c(83:107)],2,function(x) ...
: 2) Within each of the above columns there is a single numeric code, 1, 2 or
3 or an NA.
: 3) My goal is to determine the percent of time each person used a 2 code.
So if a person across these columns had
: say 8 numerical entries and if 4 of these were the number 2, the answer for
that person would be 50%.
: Best regards,
: Greg Blevins
: The Market Solutions Group
More information about the R-help