[R] Producing a table with mean values

John Kane jrkrideau at inbox.com
Sun Sep 9 14:09:32 CEST 2012


My stupdity  I made a late edit for clarity and forgot to run it to be sure I had changed everything.
It should read:
 tabx <-  ddply(meltx, .(Seamount, variable),  summarize, mean = mean(value),
 sd = sd(value))

My appologies.

John Kane
Kingston ON Canada


> -----Original Message-----
> From: smartpink111 at yahoo.com
> Sent: Sat, 8 Sep 2012 11:14:11 -0700 (PDT)
> To: jrkrideau at inbox.com
> Subject: Re: [R] Producing a table with mean values
> 
> Hi John,
> 
> I am getting error messages with your solution. tabx <-  ddply(nn,
> .(Seamount, variable),  summarize, mean = mean(value), sd = sd(value))
> #Error in empty(.data) : object 'nn' not found
> 
> A.K.
> 
> 
> 
> ----- Original Message -----
> From: John Kane <jrkrideau at inbox.com>
> To: Tinus Sonnekus <tsonnekus at gmail.com>; r-help at r-project.org
> Cc:
> Sent: Saturday, September 8, 2012 1:19 PM
> Subject: Re: [R] Producing a table with mean values
> 
> x  <-   " Seamount     Pico    Nano   Micro    Total_Ch
> Off_Mount1 0.0691 0.24200 0.00100  0.31210
> Off_Mount1 0.0938 0.00521 0.02060  0.11961
> Off_Mount1 0.1130 0.20000 0.06620  0.37920
> Off_Mount1 0.0864 0.15900 0.22300  0.46840
> Off_Mount1 0.0262 0.04570 0.00261  0.07451
> Off_Mount2 0.0314 0.17400 0.12800  0.33340
> Off_Mount2 0.0314 0.17400 0.12800  0.23340
> Off_Mount2 0.0414 0.17400 0.02800  0.23340"
> 
> xx <- read.table(textConnection(x), header=TRUE, as.is=TRUE)
> 
> library(reshape)
> meltx  <-  melt(xx)
> 
> tabx <-  ddply(nn, .(Seamount, variable),  summarize, mean = mean(value),
> sd = sd(value))
> 
> tabx
> 
> John Kane
> Kingston ON Canada
> 
> 
>> -----Original Message-----
>> From: tsonnekus at gmail.com
>> Sent: Fri, 7 Sep 2012 22:49:55 +0200
>> To: r-help at r-project.org
>> Subject: [R] Producing a table with mean values
>> 
>> Hi All,
>> 
>> I have a data set wit three size classes (pico, nano and micro) and 12
>> different sites (Seamounts). I want to produce a table with the mean and
>> standard deviation values for each site.
>> 
> >      Seamount     Pico    Nano   Micro    Total_Ch
>> 1 Off_Mount 1 0.0691 0.24200 0.00100  0.31210
>> 2 Off_Mount 1 0.0938 0.00521 0.02060  0.11961
>> 3 Off_Mount 1 0.1130 0.20000 0.06620  0.37920
>> 4 Off_Mount 1 0.0864 0.15900 0.22300  0.46840
>> 5 Off_Mount 1 0.0262 0.04570 0.00261  0.07451
>> 6 Off_Mount 2 0.0314 0.17400 0.12800  0.33340
>> 
>> I tried the following script but get an error message
>> 
>> *Error in results[i, "u.Pico", "u.Nano", "u.Micro"] <- sapply(z, mean) :
>> *
>> *  incorrect number of subscripts *
>> 
>> The code I used:
>> 
>> *SChla <- read.csv("SM_Chla_data.csv")*
>> *sm <- as.character(unique(SChla$Seamount))*
>> *
>> *
>> *results <-
>> matrix(NA,nrow=length(sm),ncol=6,dimnames=list(sm,c("u.Pico","u.Nano","u.Micro","sd.Pico","sd.Nano","sd.Micro")))
>> *
>> *
>> *
>> *for (i in sm){*
>> *z <- subset(SChla, Seamount==i, select=c(Pico, Nano, Micro))*
>> *results[i,"u.Pico","u.Nano","u.Micro"] <- sapply(z, mean)*
>> *results[i,"sd.Pico","sd.Nano","sd.Micro"] <- sapply(z, sd)*
>> *}*
>> *
>> *
>> *print(results)*
>> 
>> Please can some one advise me how to fix the error or maybe have an
>> alternative solution I will appreciate it.
>> 
>> Thank you.
>> Tinus
>> 
>>     [[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.
> 
> ____________________________________________________________
> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
> http://www.inbox.com/smileys
> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™
> and most webmails
> 
> ______________________________________________
> 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.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!




More information about the R-help mailing list