[R] odd behavior when multiplying data frame by an element

markleeds at verizon.net
Sat, 13 Dec 2008 01:52:18 -0000

could someone explain what is happening below ? I was trying to solve a
related question on the list and then , as I was solving it,
I was getting strange answers and then I noticed below. It's obviously
not a bug but I don't get it. Thanks.

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

print(m)
m[,-1]*2       # THIS IS FINE
m[,"jet"]*2     # THIS IS FINE


print(d1["jet"]) # THIS IS FINE
m[,"jet"]*d1["jet"] # THIS IS ODD