[R] Hidden information in an object
Ista Zahn
istazahn at gmail.com
Thu Feb 28 21:55:00 CET 2013
Hi Rasmus,
Things will be much less confusing if you don't use attach. I know
that sounds flippent, but I'm quite serious.
Best,
Ista
On Thu, Feb 28, 2013 at 7:50 AM, Rasmus Hedegaard
<hedegaard_84 at hotmail.com> wrote:
>
>
>
>
> Hello, The dataset "cats" contain information about the heart weight ("Hwt"), body weight ("Bwt") and gender ("Sex") of a group of 144 cats. I write the following piece of code: library(MASS)attach(cats)ratio <- Hwt/Bwtmale <- ratio[Sex == "M"]female <- ratio[Sex == "F"] My question is, when I look at the object "ratio", it is just a list of 144 numbers with no information about the gender of the cat that the ratio comes from, and yet the command "ratio[Sex == "M"]" is able to pick out those numbers of "ratio" for which the corresponding cat is male. Why is this? If I write the code like library(MASS)cats$ratio <- cats$Hwt/cats$Bwtmale <- cats$ratio[cats$Sex == "M"]... it also works, which I suppose is because there is a correspondence between the "Sex" variable and the "ratio" variable in the cats dataset. Regards,Rasmus Hedegaard.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list