| To: | "'Eva Goldwater'" <goldwater@schoolph.umass.edu>, <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Re: BY with stdev? |
| From: | <Rich@mango-solutions.com> |
| Date: | Tue, 21 Dec 2004 18:45:20 -0000 |
| In-reply-to: | <Pine.GSO.4.55.0412211317320.22443@shell1.oit.umass.edu> |
| Thread-index: | AcTnixmmzfaMxep7TeGB7bkoMUJW9wAAdIvA |
|
Hi Eva, You need "tapply", not "by". By is primarily used to split list-based structures by one or more factors. The "tapply" function splits a vector by one or more factors ...... > by(fuel.frame$Mileage, fuel.frame$Type, mean) INDICES:Compact [1] 24.13333 ---------------------------------------------------------------------------------------------------INDICES:Large [1] 20.33333 ---------------------------------------------------------------------------------------------------INDICES:Medium [1] 21.76923 ---------------------------------------------------------------------------------------------------INDICES:Small [1] 31 ---------------------------------------------------------------------------------------------------INDICES:Sporty [1] 26 ---------------------------------------------------------------------------------------------------INDICES:Van [1] 18.85714 > by(fuel.frame$Mileage, fuel.frame$Type, stdev) Problem in as.double: Cannot coerce mode list to double: list(c(27., 23., 26., 25., 24., 26., 24., 25., 21., 21., 23., 24., 23., 27., 23.)) Use traceback() to see the call stack > tapply(fuel.frame$Mileage, fuel.frame$Type, mean) Compact Large Medium Small Sporty Van 24.13333 20.33333 21.76923 31 26 18.85714 > tapply(fuel.frame$Mileage, fuel.frame$Type, stdev) Compact Large Medium Small Sporty Van 1.884776 2.516611 0.9268087 3.807887 4.472136 0.8997354 Hope this helps, Rich. mangosolutions R and S Consulting and Training Tel +44 118 902 6617 Fax +44 118 902 6401 -----Original Message----- Hello, I tried to get standard deviations for subgroups of a numeric column, defined by another column. I'm using the by function, but it doesn't work with stdev. It's fine with mean or summarize, but not stdev or stderr. Here is my test. (This is S-Plus 6.2 on Windows.) x <- data.frame(cbind(x1=rep(1:2,5), x2=runif(10))) by(x$x2,x$x1,mean) by(x$x2,x$x1,stdev) Problem in as.double: Cannot coerce mode list to double: list(c(0.361767916940153, 0.132468292489.... Use traceback() to see the call stack by(x$x2,x$x1,stderr) Problem in FUN(...X.sub.i...., str..: Too many arguments(1) in call to "FUN"; last 1 not matched Use traceback() to see the call stack What's the problem? Incidentally, ?stderr takes me to help for the file() function... Thanks for your insights. Eva Eva Goldwater email: goldwater@schoolph.umass.edu Biostatistics Consulting Phone: (413) 545-2949 418 Arnold House Fax: (413) 545-1645 715 North Pleasant Street University of Massachusetts Amherst, MA 01003-9304 -------------------------------------------------------------------- This message was distributed by s-news@lists.biostat.wustl.edu. To unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with the BODY of the message: unsubscribe s-news |
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | BY with stdev?, Eva Goldwater |
|---|---|
| Next by Date: | Re: BY with stdev?, Tony Plate |
| Previous by Thread: | BY with stdev?, Eva Goldwater |
| Next by Thread: | Re: BY with stdev?, Tony Plate |
| Indexes: | [Date] [Thread] [Top] [All Lists] |