An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120907/b14b3350/attachment.pl>
Producing a table with mean values
7 messages · Tinus Sonnekus, David Winsemius, Rui Barradas +3 more
On Sep 7, 2012, at 1:49 PM, Tinus Sonnekus wrote:
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
Assuming this is a dataframe named "dat"...
with(dat, aggregate(cbind(Pico, Nano, Micro), list(Seamount), FUN=mean))
Group.1 Pico Nano Micro 1 Off_Mount 0.06998333 0.1376517 0.07356833
David.
>
> 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.
David Winsemius, MD
Alameda, CA, USA
Hello,
Try the following.
agg1 <- aggregate(cbind(Pico, Nano, Micro) ~ Seamount, data = SChla, mean)
agg2 <- aggregate(cbind(Pico, Nano, Micro) ~ Seamount, data = SChla, sd)
names(agg1)[-1] <- paste("u", names(agg1)[-1], sep = ".")
names(agg2)[-1] <- paste("sd", names(agg2)[-1], sep = ".")
merge(agg1, agg2)
Hope this helps,
Rui Barradas
Em 07-09-2012 21:49, Tinus Sonnekus escreveu:
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.
On 12-09-07 4:49 PM, Tinus Sonnekus wrote:
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
Something like this could work: library(tables) tabular( Seamount ~ (Pico + Nano + Micro)*mean, data=SChla) There are lots of variations, e.g. if you want the size classes as rows and the Seamounts as columns, tabular( (Pico + Nano + Micro) ~ Seamount*mean, data=SChla) It will also output LaTeX tables if you ask for them. Duncan Murdoch
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.
Hi,
Try this:
dat1<-read.table(text="
?Seamount??? Pico??? Nano? Micro??? Total_Ch
? 1 0.0691 0.24200 0.00100? 0.31210
? 1 0.0938 0.00521 0.02060? 0.11961
? 1 0.1130 0.20000 0.06620? 0.37920
? 1 0.0864 0.15900 0.22300? 0.46840
? 1 0.0262 0.04570 0.00261? 0.07451
? 2 0.0314 0.17400 0.12800? 0.33340
",sep="",header=TRUE,stringsAsFactors=FALSE)
library(data.table)
dat2<-data.table(dat1)
dat2mean<-dat2[,list(Pico=.Internal(mean(Pico)),Nano=.Internal(mean(Nano)),Micro=.Internal(mean(Micro))),by="Seamount"]
dat2mean
#?? Seamount?? Pico???? Nano??? Micro
#1:??????? 1 0.0777 0.130382 0.062682
#2:??????? 2 0.0314 0.174000 0.128000
dat2sd<-dat2[,list(sdPico=sd(Pico),sdNano=sd(Nano),sdMicro=sd(Micro)),by="Seamount"]
dat2sd
#? Seamount???? sdPico?? sdNano??? sdMicro
#1:??????? 1 0.03281463 0.101197 0.09340563
#2:??????? 2???????? NA?????? NA???????? NA
?dat3comb<-data.frame(cbind(dat2mean,dat2sd))
?dat3comb[,-5]
? Seamount?? Pico???? Nano??? Micro???? sdPico?? sdNano??? sdMicro
1??????? 1 0.0777 0.130382 0.062682 0.03281463 0.101197 0.09340563
2??????? 2 0.0314 0.174000 0.128000???????? NA?????? NA???????? NA
A.K.
----- Original Message -----
From: Tinus Sonnekus <tsonnekus at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Friday, September 7, 2012 4:49 PM
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.
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
HI John, I got it.? Please disregard my previous email. I guess the code should be: tabx <-? ddply(meltx, .(Seamount, variable),? summarize, mean = mean(value), sd = sd(value)) 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.