Re: [R] conditional rowsums in sapply

2011-05-16 Thread Assu
Hello David, I'm not sure I get your question; if you replied to SO, I had not seen it. I posted there today. I'm reading it now! I chose not to receive replies in my email from SO but I must change that. Thank you for making me see that! Sorry, I'm new to R-help and, especially, SO. Thanks for y

Re: [R] conditional rowsums in sapply

2011-05-16 Thread David Winsemius
On May 16, 2011, at 10:25 AM, Assu wrote: Hi all I have a data frame with duplicate columns and i want to remove duplicates by adding rows in each group of duplicates, but have lots of NA's. Data: dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4) names(dfrm) <- c("a", "a", "b",

Re: [R] conditional rowsums in sapply

2011-05-16 Thread Dimitris Rizopoulos
assuming that the row entries for the columns with the same name are not all zero, you can try something in the following lines: dfrm <- data.frame(a = 1:4, a = 1:4, b = 1:4, b = 1:4, b = 1:4, check.names = FALSE) dfrm[3, 1:3] <- NA dfrm vals <- unlist(dfrm) res <- tapply(vals, names(vals),

[R] conditional rowsums in sapply

2011-05-16 Thread Assu
Hi all I have a data frame with duplicate columns and i want to remove duplicates by adding rows in each group of duplicates, but have lots of NA's. Data: dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4) names(dfrm) <- c("a", "a", "b", "b", "b") dfrm[3,2:3]<-NA dfrm a a b b b