Skip to content
Prev 95417 / 398500 Next

difficult data manipulation question

Try this:

# test data
# read in header separately so R does not make column names unique
Lines <- "AAA BBB CCC DDD AAA BBB
   0      2      1     2      0      0
   2      3      7     6      0      1
   1.5    4      9     9      6      0
   1.0    6      10    11     3      3
"
DF <- read.table(textConnection(Lines), skip = 1)
names(DF) <- scan(textConnection(Lines), what = "", nlines = 1)

f <- function(x) x[which.max(colSums(DF[x]!=0))]
tapply(seq(DF), names(DF), f)
On 7/3/06, markleeds at verizon.net <markleeds at verizon.net> wrote: