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

markleeds at verizon.net
Sat, 13 Dec 2008 02:06:14 -0000

disregard my last question. i forgot that d1 was a dataframe and was
thinkiing it was a vector. i think i can fix what i was doing now.




On Fri, Dec 12, 2008 at  8:52 PM, markleeds at verizon.net wrote:

> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.