Message-ID: <1A8C1289955EF649A09086A153E2672403E14A94D2@GBTEDVPEXCMB04.corp.lgc-group.com>
Date: 2016-05-27T10:37:31Z
From: S Ellison
Subject: subset data right
In-Reply-To: <CAF8bMcZ+QfavNVdpTJ+29XAbRbEQ1ExN0CKJqNKhJKD96t3aKQ@mail.gmail.com>
> You did not change df$quant - you made a new object called 'subdf'
> containing a column called 'quant' that had only one level. Changing subdf has
> no effect on df.
Also, subsetting a factor _intentionally_ does not change the number of levels. Example:
f <- factor(sample(letters[1:3], 30, replace=TRUE))
f[1] #One element, still three levels
If you want to drop levels, use droplevels() either on the factor or on the subset of your data frame. Example:
droplevels(f[1]) #One element, only one level
Also worth noting that df is a function.
> df <- data.frame(quant=factor(letters))
looks very like you're assigning a data frame to the function 'df' (density for the F distribution)
It doesn't, because R is clever. But it's really not good practice to use common function names as variable names. Too much potential for confusion.
S Ellison
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}