Thank you for your help!
It works beautifully, but how would I transpose the results?

What I am getting is indeed:

7200          23955        34563        8934
16.39977 10.03896    11.234      14.02

I'd like the final output to be:

subject_id         hr_Stand_Deviation
7200                  16.39977
23955                10.03896
34563                11.234
8934                  14.02

What I have realized so far is:

tapply() is outputting an array, so I need to transpose the array.
Then I read that you need to use aperm to transpose an array, but I don' t
know what permutation vector I should choose
Then even if it is transposed, I'd like to retitle the columns to be
'subject_id' and 'hr_standard_deviation'

I tried to convert the array to a table and then to a matrix, but I'm not
sure what the best way to go is from this point.

Thanks again!



On Thu, Nov 20, 2008 at 12:17 AM, Simon Blomberg <[EMAIL PROTECTED]>wrote:

> 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 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
> attempting
> > to compute SD in SQL, or is this easily accomplished in R?
> >
> >
> > *      SUBJECT_ID  HR
> > 1        7200 158
> > 2        7200 165
> > 3        7200 138
> > 4        7200 152
> > 5        7200 139
> > 6        7200 157
> > 7        7200 186
> > 8       23955 167
> > 9       23955 162
> > 10      23955 171
> > 11      23955 139
> > 12      23955 170
> > 13      23955 177
> > 14      23955 180
> > 15      23955 176
> > 16      23955 172
> > 17      23955 179
> > 18      23955 181
> > 19      23955 169
> > 20      23955 168
> > 21      23955 185
> > 22      23955 181
> > 23      23955 191
> > 24      23955 179
> > 25      23955 178
> > 26      23955 184
> > 27      23955 179
> > 28      23955 172
> > 29      23955 173
> > 30      23955 182
> > 31      23955 174
> >
> > *
> > So, what I would want is a table of 800 patients with a SD for their
> heart
> > rates:
> >
> > subject id       Heart Rate SD
> >
> > 7200              20 (for example)
> > 23955           18 (for example)*
> >
> > Thank you!
> >
> >       [[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.
> --
> Simon Blomberg, BSc (Hons), PhD, MAppStat.
> Lecturer and Consultant Statistician
> Faculty of Biological and Chemical Sciences
> The University of Queensland
> St. Lucia Queensland 4072
> Australia
> Room 320 Goddard Building (8)
> T: +61 7 3365 2506
> http://www.uq.edu.au/~uqsblomb <http://www.uq.edu.au/%7Euqsblomb>
> email: S.Blomberg1_at_uq.edu.au
>
> Policies:
> 1.  I will NOT analyse your data for you.
> 2.  Your deadline is your problem.
>
> The combination of some data and an aching desire for
> an answer does not ensure that a reasonable answer can
> be extracted from a given body of data. - John Tukey.
>
>

        [[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.

Reply via email to