Re: [R] Sapply for descriptive statistics

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Wed, 09 Mar 2011 18:35:00 -0500

Sent from my iPhone

On Mar 9, 2011, at 6:13 PM, David Winsemius <dwinsemius_at_comcast.net> wrote:

> 
> 
> Sent from my iPhone
> 
> On Mar 9, 2011, at 5:59 PM, Tomii <diogenas_at_gmail.com> wrote:
> 

>> I try to calculate descriptive statistics for one of the variables in the
>> data frame, however command sapply calculates these statistics for every
>> value of the variable separately. How to make it calculate range (as well as
>> other statistics) for all column?
>>
> If you want range of all columns try:
> 
> sapply(as1, range)

To expand: you sent separate values to range. If you had tried: sapply(as1["trust"], range)
pply(as1["trust"], range)
... you should have succeeded.

> 
> -- 
> David

>> Here are commands and results:
>>
>>> as1$trust

>> [1] 5.957510 5.888664 6.168135 6.419472 5.668796 6.026923
>> 6.456721 7.017946 5.294411
>>
>> [10] 7.296844 6.479167 5.009000 7.149073 5.932667 5.991000
>> 5.327137 5.453230 5.650350
>> [19] 5.295608 5.518337 4.875000 6.637000 5.891014 6.726055
>> 10.695650 5.490983 7.290476
>> [28] 5.728543 4.103689 8.421315
>>> des.trust <- sapply(as1$trust, range, na.rm=TRUE)
>>> des.trust

>> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
>> [,8] [,9] [,10]
>> [1,] 5.95751 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721
>> 7.017946 5.294411 7.296844
>> [2,] 5.95751 5.888664 6.168135 6.419472 5.668796 6.026923 6.456721
>> 7.017946 5.294411 7.296844
>>
>> [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18]
>> [,19] [,20] [,21]
>> [1,] 6.479167 5.009 7.149073 5.932667 5.991 5.327137 5.45323 5.65035
>> 5.295608 5.518337 4.875
>> [2,] 6.479167 5.009 7.149073 5.932667 5.991 5.327137 5.45323 5.65035
>> 5.295608 5.518337 4.875
>>
>> [,22] [,23] [,24] [,25] [,26] [,27] [,28]
>> [,29] [,30]
>> [1,] 6.637 5.891014 6.726055 10.69565 5.490983 7.290476 5.728543
>> 4.103689 8.421315
>> [2,] 6.637 5.891014 6.726055 10.69565 5.490983 7.290476 5.728543
>> 4.103689 8.421315
>>
>>
>> tomii <t.klepsys_at_gmail.com>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 09 Mar 2011 - 23:37:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Mar 2011 - 00:00:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive