[R] help with data layout

Henrique Dallazuanna wwwhsd at gmail.com
Thu Jul 17 18:24:00 CEST 2008


Try this:

#x <- read.csv('your_file.csv')

x$Col1 <- rep(as.character(x$Col1[x$Col1!="" ]),
              each = unique(diff(which(x$Col1 != ""))))
with(x, sapply(c(sd, mean), function(x)tapply(Col2, Col1, x)))

On Thu, Jul 17, 2008 at 12:50 PM, Iain Gallagher
<iaingallagher at btopenworld.com> wrote:
> Hello list
>
> I have been given some Excel sheets with data laid like this:
>
> Col1    Col2
> A         3
>           2
>           3
> B         4
>           5
>           4
> C         1
>           4
>           3
>
> I was hoping to import this into R as a csv and then get the mean and SD for each letter in column 1.
>
> Could someone give me some guidance on best to approach this?
>
> Thanks
>
> Iain
>
>        [[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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list