[R] Dataframe: Average cells of two rows and replace them with one row

arun smartpink111 at yahoo.com
Wed May 28 03:48:05 CEST 2014


Hi,
You can also try:
dat <- read.table(text="Name C1 C2 C3
  1  A  3  3  5
  2  B  2  7  4
  3  C  4  3  3
  4  C  4  4  6
  5  D  5  5  3",sep="",header=TRUE,stringsAsFactors=FALSE)


 library(plyr)
 ddply(dat,.(Name),numcolwise(mean,na.rm=TRUE))
A.K.


On Tuesday, May 27, 2014 4:08 PM, Verena Weinbir <vweinbir at gmail.com> wrote:
Hello,

I have a big dataframe, and want to average two specific cells of two
specific rows and then replace those two rows with one row which contains
the averaged cells. Example (row 3 and 4: Cells2 and Cells3 averaged and
replaced)

    NameC1 C2 C3
  1  A  3  3  5
  2  B  2  7  4
  3  C  4  3  3
  4  C  4  4  6
  5  D  5  5  3



    NameC1 C2  C3
  1  A  3  3   5
  2  B  2  7   4
  3  C  4  3.5 4.5  4  D  5  5   3


Many thanks in advance!

Best,

Verena

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



More information about the R-help mailing list