>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
Calling factor() on a factor, as the OP did, also drops any unused levels,
as the examples showed.
>
> 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],
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.
> df <- data.frame(quant=factor(letters))
> str(df)
'data.frame': 26 obs. of 1 variable:
$ quant: Factor w/ 26 levels
Hello,
Don't use subset, use indexing.
subdf <- df[df$quant %in% "VeryFast", ]
By the way, instead of %in% you can use ==, since you're interested in
just one value of quant.
Hope this helps,
Rui Barradas
Citando ch.elahe via R-help :
> Hi all,
> I have the following
Hi all,
I have the following df and I want to know which Protocols are VeryFast, which
are FAST, which are SLOW and also which ones are VerySLOW :
$ Protocol : Factor w/ 48 levels "DP FS QTSE SAG",..: 5 5 28 5 5 5 7 7
47 5 ...
$ quant : Factor w/ 4 levels
5 matches
Mail list logo