[R] How do I coerce numeric factor columns of data frame to vector?
Michael A. Miller
mmiller3 at iupui.edu
Tue Sep 9 01:06:56 CEST 2003
>>>>> "Murray" == Murray Jorgensen <maj at stats.waikato.ac.nz> writes:
> I have just noticed that quite a few columns of a data
> frame that I am working on are numeric factors. For
> summary() purposes I want them to be vectors.
Do you want them to be vectors or do you want numeric values? If
the later, try as.numeric instead of as.vector:
> as.vector(factor(rep(seq(4),3)))
[1] "1" "2" "3" "4" "1" "2" "3" "4" "1" "2" "3" "4"
> as.numeric(factor(rep(seq(4),3)))
[1] 1 2 3 4 1 2 3 4 1 2 3 4
> summary(as.vector(factor(rep(seq(4),3))))
Length Class Mode
12 character character
> summary(as.numeric(factor(rep(seq(4),3))))
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.00 1.75 2.50 2.50 3.25 4.00
Mike
More information about the R-help
mailing list