[R] factor levels on import
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sat Apr 22 13:02:41 CEST 2006
Stephen C. Upton wrote:
> I have a data frame that I plan on importing from a file (there are
> other columns of numeric data):
> > xy
> x y
> 1 1 1
> 2 1 1
> 3 1 1
> 4 1 1
> 5 2 2
> 6 2 2
> 7 2 2
> 8 2 2
> >
>
> where x is a column of factors, and y is a column of factors, that have
> different levels, e.g.,
> > x
> [1] low low low low hi hi hi hi
> Levels: low hi
> > y
> [1] med med med med medhi medhi medhi medhi
> Levels: med medhi
>
> How do I get the columns to use the combined levels
> c("low","med","medhi","high") so that the data frame is actually:
> > xy
> x y
> 1 1 2
> 2 1 2
> 3 1 2
> 4 1 2
> 5 4 3
> 6 4 3
> 7 4 3
> 8 4 3
> >
>
1. R treads each factor separately
2. R cannot know the levels, in particular not that you want to shift
the representation.
=> you have to do the job more or less manually
Uwe Ligges
> I'm sure there's a way to lapply or some such, but haven't broken the
> code. I'm also sure I'm missing something simple.
>
> thanx
> steve
>
>
> R 2.2.1
> Windows XP
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list