Hi:
Using the plyr package,
summarise(dd, b = b, wx = (w + x)/2, yz = (y + z)/2)
b wx yz
1 chr2 6 4.5
2 chr1 7 2.0
3 chrY 8 5.0
4 chr13 9 5.5
5 chrX 10 7.5
HTH,
Dennis
On Sun, Jun 6, 2010 at 9:53 PM, Yuan Jian <jayuan2008@yahoo.com> wrote:
> Hi R experts.
>
> how can I average two sets of columns?
>
> dd <- data.frame(b = c("chr2", "chr1",
"chrY", "chr13", "chrX"),
> w=11:15, x = 1:5, y = c(8, 3, 9, 9,7),
> z = c(1, 1, 1, 2, 8))
> expected result for mean(w,x) and mean(y,z) is
> 1 chr2 6 4.5
> 2 chr1 7 2
> 3 chrY 8 5
> 4 chr13 9 5.5
> 5 chrX 10 7.5
>
> Yu
>
>
>
>
>
> [[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.
>
>
[[alternative HTML version deleted]]