[R] feather and jet problem

markleeds at verizon.net markleeds at verizon.net
Sat Dec 13 03:15:29 CET 2008


to the person who just asked about the feather and jet problem: i lost 
your email but below works. there should be a shorter way by
avoiding the last statement and doing everything in the lapply but I've 
had enough of feathers and jets tonight.

m <- data.frame(class = c("birds", "planes"), feather = c(1,3), jet = 
c(2,4))
d1 <- data.frame(jet = c(10), feather = c(20))

result <- lapply(names(m[,-1]), function(.name) {
           m[[.name]]*d1[[.name]]
         })

result <- data.frame(m$class,feather=result[[1]],jet=result[[2]])
print(result)



More information about the R-help mailing list