Re: [R] Adding columns of Aggregates to existing dataframe
Thanks. ave() is the exact function I was after. tonyxv wrote: > > Hello, > I have a dataframe > > > ID1 ID2 > A1B3 > A1B4 > A1B3 > A1B3 > A2B1 > A2B1 > A2B4 > A3B2 > A3B2 > A5B1 > A5B1 > A5B6 > A5B4 > A6B2 > > > > I want to add e
Re: [R] Adding columns of Aggregates to existing dataframe
This should do it for you: > x <- read.table(textConnection("ID1 ID2 + A1B3 + A1B4 + A1B3 + A1B3 + A2B1 + A2B1 + A2B4 + A3B2 + A3B2 + A5B1 + A5B1 + A5B6 + A5B4 + A6B2"), header=TRUE) > cbind(x, countID1=ave(seq_along(x$ID1), x$ID1, FUN=leng