Re: [R] Equivalent to a BY command in SAS

2008-04-14 Thread zerfetzen

Thanks all.  I will try to use both tapply and by, and have no idea how I
missed the by function.  Thanks again.
-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-a-BY-command-in-SAS-tp16670452p16676280.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Equivalent to a BY command in SAS

2008-04-14 Thread Duncan Murdoch
On 4/14/2008 7:30 AM, zerfetzen wrote:
 Thanks all.  I will try to use both tapply and by, and have no idea how I
 missed the by function.  Thanks again.

One problem with both of those arises if you are subsetting on several 
columns.  They will do the calculations for all combinations of all 
columns, even if only a few combinations of levels are present in your 
dataset.  This can make the calculation take up a large amount of memory.

I wrote the sparseby function to handle this case; it is in the reshape 
package.

Duncan Murdoch

__
R-help@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.


Re: [R] Equivalent to a BY command in SAS

2008-04-14 Thread Michael Kubovy
You might also take a look at the doBy package.

On Apr 14, 2008, at 7:30 AM, zerfetzen wrote:

 Thanks all.  I will try to use both tapply and by, and have no idea  
 how I
 missed the by function.  Thanks again.

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/



[[alternative HTML version deleted]]

__
R-help@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] Equivalent to a BY command in SAS

2008-04-13 Thread zerfetzen

Hi,
I'm very new to R and absolutely love it.  Does anyone know how to use
something in R that functions like a BY command in SAS?

For example, let's say you have a variable x, and you want to see the mean. 
Easy...

 mean(x)

But what if you want to see the mean of x conditional on another discrete
variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

...which of course doesn't work.  I have downloaded plenty of R user guides
that are very informative, but am not seeing much on detailed descriptives
or data manipulation (for my life, I can't figure out how to sort an
attached data frame, but that's another issue).  Thanks.
-- 
View this message in context: 
http://www.nabble.com/Equivalent-to-a-BY-command-in-SAS-tp16670452p16670452.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Equivalent to a BY command in SAS

2008-04-13 Thread Dylan Beaudette
On Sun, Apr 13, 2008 at 7:36 PM, zerfetzen [EMAIL PROTECTED] wrote:

  Hi,
  I'm very new to R and absolutely love it.  Does anyone know how to use
  something in R that functions like a BY command in SAS?

  For example, let's say you have a variable x, and you want to see the mean.
  Easy...

   mean(x)

  But what if you want to see the mean of x conditional on another discrete
  variable?  My best attempts so far are something like...

Using the built-in dataset 'CO2' :

# compute the mean 'conc' for every level of 'Plant'
tapply(CO2$conc, CO2$Plant, FUN=mean)

Qn1 Qn2 Qn3 Qc1 Qc3 Qc2 Mn3 Mn2 Mn1 Mc2 Mc3 Mc1
435 435 435 435 435 435 435 435 435 435 435 435

?tapply for details
?by for more details


Dylan


   mean(x, y_cat=1)

  ...which of course doesn't work.  I have downloaded plenty of R user guides
  that are very informative, but am not seeing much on detailed descriptives
  or data manipulation (for my life, I can't figure out how to sort an
  attached data frame, but that's another issue).  Thanks.
  --
  View this message in context: 
 http://www.nabble.com/Equivalent-to-a-BY-command-in-SAS-tp16670452p16670452.html
  Sent from the R help mailing list archive at Nabble.com.

  __
  R-help@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@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.


Re: [R] Equivalent to a BY command in SAS

2008-04-13 Thread Vincent Goulet
Le dim. 13 avr. à 22:36, zerfetzen a écrit :

 Hi,
 I'm very new to R and absolutely love it.  Does anyone know how to use
 something in R that functions like a BY command in SAS?

 For example, let's say you have a variable x, and you want to see  
 the mean.
 Easy...

 mean(x)

 But what if you want to see the mean of x conditional on another  
 discrete
 variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

 ...which of course doesn't work.  I have downloaded plenty of R user  
 guides
 that are very informative, but am not seeing much on detailed  
 descriptives
 or data manipulation (for my life, I can't figure out how to sort an
 attached data frame, but that's another issue).  Thanks.

You didn't give much detail about what exactly you want to do (have a  
look at the Posting Guide), but... perhaps by() will do what you what.  
See ?by .

Bye!

---
   Vincent Goulet, Associate Professor
   École d'actuariat
   Université Laval, Québec
   [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@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.


Re: [R] Equivalent to a BY command in SAS

2008-04-13 Thread Rolf Turner

On 14/04/2008, at 2:36 PM, zerfetzen wrote:


 Hi,
 I'm very new to R and absolutely love it.  Does anyone know how to use
 something in R that functions like a BY command in SAS?

 For example, let's say you have a variable x, and you want to see  
 the mean.
 Easy...

 mean(x)

 But what if you want to see the mean of x conditional on another  
 discrete
 variable?  My best attempts so far are something like...

 mean(x, y_cat=1)

 ...which of course doesn't work.  I have downloaded plenty of R  
 user guides
 that are very informative, but am not seeing much on detailed  
 descriptives
 or data manipulation (for my life, I can't figure out how to sort an
 attached data frame, but that's another issue).  Thanks.

  set.seed(42)
  x - rnorm(100)
  y - sample(letters[1:3],100,TRUE)
  by(x,y,mean)
INDICES: a
[1] 0.1089523

INDICES: b
[1] -0.2253035

INDICES: c
[1] 0.2997985

Or:

   tapply(x,y,mean)
  a  b  c
  0.1089523 -0.2253035  0.2997985

cheers,

Rolf Turner


##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
R-help@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.