Re: [R] Calculating SD according to groups of rows

2008-11-20 Thread hadley wickham
On Thu, Nov 20, 2008 at 10:04 AM, Dieter Menne <[EMAIL PROTECTED]> wrote: > hadley wickham gmail.com> writes: > >> > library(plyr) >> > dat = data.frame(SUBJECT_ID=sample(letters[1:5],100,TRUE),HR=rnorm(100)) >> > daply(dat,.(SUBJECT_ID),sd) >> > ddply(dat,.(SUBJECT_ID),sd) >> >> Well that calcula

Re: [R] Calculating SD according to groups of rows

2008-11-20 Thread Dieter Menne
hadley wickham gmail.com> writes: > > library(plyr) > > dat = data.frame(SUBJECT_ID=sample(letters[1:5],100,TRUE),HR=rnorm(100)) > > daply(dat,.(SUBJECT_ID),sd) > > ddply(dat,.(SUBJECT_ID),sd) > > Well that calculates sd on the whole data frame. (Like sd(dat)). Not really, it looks like the b

Re: [R] Calculating SD according to groups of rows

2008-11-20 Thread hadley wickham
On Thu, Nov 20, 2008 at 2:20 AM, Dieter Menne <[EMAIL PROTECTED]> wrote: > pufftissue pufftissue gmail.com> writes: > >> >> What I am getting is indeed: >> >> 7200 23955345638934 >> 16.39977 10.0389611.234 14.02 >> >> I'd like the final output to be: >> >> subject

Re: [R] Calculating SD according to groups of rows

2008-11-20 Thread Petr PIKAL
What about aggregate. with(dat, aggregate(HR, list(sub_id=SUBJECT_ID), sd)) shall result in required final output form. Regards Petr [EMAIL PROTECTED] napsal dne 20.11.2008 09:20:36: > pufftissue pufftissue gmail.com> writes: > > > > > What I am getting is indeed: > > > > 7200 23

Re: [R] Calculating SD according to groups of rows

2008-11-20 Thread Dieter Menne
pufftissue pufftissue gmail.com> writes: > > What I am getting is indeed: > > 7200 23955345638934 > 16.39977 10.0389611.234 14.02 > > I'd like the final output to be: > > subject_id hr_Stand_Deviation > 7200 16.39977 > 23955

Re: [R] Calculating SD according to groups of rows

2008-11-19 Thread pufftissue pufftissue
Thank you for your help! It works beautifully, but how would I transpose the results? What I am getting is indeed: 7200 23955345638934 16.39977 10.0389611.234 14.02 I'd like the final output to be: subject_id hr_Stand_Deviation 7200 16.

Re: [R] Calculating SD according to groups of rows

2008-11-19 Thread Simon Blomberg
How about: with(dat, tapply(HR, SUBJECT_ID, sd)) Assuming your data frame is named dat. On Wed, 2008-11-19 at 23:59 -0500, pufftissue pufftissue wrote: > *Hi all, > > I know this is probably basic, but I have proven to be a slow learner in any > programming language. Anyhow, > how can I calcu

Re: [R] Calculating SD according to groups of rows

2008-11-19 Thread Jorge Ivan Velez
Dear pufftissue, If your data set is a data.frame called 'x', one approach could be: # Data set x=read.table('clipboard',header=TRUE) # Calculations tapply(x$HR,x$SUBJECT_ID,sd,na.rm=TRUE) 720023955 16.39977 10.03896 See ?tapply and/or ?ave for more information. HTH, Jorge On Wed, N

[R] Calculating SD according to groups of rows

2008-11-19 Thread pufftissue pufftissue
*Hi all, I know this is probably basic, but I have proven to be a slow learner in any programming language. Anyhow, how can I calculate the SD for each person in my table? I have two patients in this R data.frame, 7200 and 23955. I extracted this from a relational database, but am I better off