Hello,
I've recently returned to Splus after a long layoff (forced SAS treatments).
I'm trying to apply "by" for various input functions and datasets and having
trouble getting it right.
For example, I can create a dataframe as follows:
tempdata<-as.data.frame(matrix(NA,4,4))
names(tempdata)<-c("yearmon","h0","h1","name")
tempdata[1,]<-c(200602,1,4,"abvol")
tempdata[2,]<-c(200603,2,3,"abvol")
tempdata[3,]<-c(199106,3,2,"accr")
tempdata[4,]<-c(199107,4,1,"accr")
With results that look like this:
> tempdata
yearmon h0 h1 name
1 200602 1 4 abvol
2 200603 2 3 abvol
3 199106 3 2 accr
4 199107 4 1 accr
I want to compute various functions (min, max, mean, stdev, kurtosis, etc.)
over the groups defined in the "name" variable using the "by" function.
On some data sets I can get "mean" to work fine but not the others.
On the example above, I get the following results using "mean"
by(as.data.frame(tempdata[,1]), tempdata$name, mean)
> by(as.data.frame(tempdata[, 1]), tempdata$name, mean)
tempdata$name:abvol
[1] NA
-----------------------------------------------------------
tempdata$name:accr
[1] NA
On the example above, I get the following results using "min"
by(as.data.frame(tempdata[,1]), tempdata$name, mean)
> by(as.data.frame(tempdata[, 1]), as.factor(tempdata$name),
min)
Problem in NextMethod(.Generic): Can't find the generic
function "FUN"
Use traceback() to see the call stack
Would someone please explain to me how I can make these work?
I'm running Splus 7.0 on Windows 2000.
Thanks!
Matt
This message and any attachments are confidential, proprietary, and may be
privileged. If this message was misdirected, Barclays Global Investors (BGI)
does not waive any confidentiality or privilege. If you are not the intended
recipient, please notify us immediately and destroy the message without
disclosing its contents to anyone. Any distribution, use or copying of this
e-mail or the information it contains by other than an intended recipient is
unauthorized. The views and opinions expressed in this e-mail message are the
author's own and may not reflect the views and opinions of BGI, unless the
author is authorized by BGI to express such views or opinions on its behalf.
All email sent to or from this address is subject to electronic storage and
review by BGI. Although BGI operates anti-virus programs, it does not accept
responsibility for any damage whatsoever caused by viruses being passed.
|