Is this what you're going for?
factor(values, levels=mylevels[[1]], labels=mylevels[[2]])
[1] a b e e j
Levels: a b c d e f g h i j
On 2014-03-28 16:38, Jonathan Greenberg wrote:
R-helpers:
Hopefully this is an easy one. Given a lookup table:
mylevels -
On Mar 28, 2014, at 1:52 PM, Noah Marconi wrote:
Is this what you're going for?
factor(values, levels=mylevels[[1]], labels=mylevels[[2]])
[1] a b e e j
Levels: a b c d e f g h i j
That is certainly what looks like the right (or at least obvious) answer to me.
The OP should note that
R-helpers:
Hopefully this is an easy one. Given a lookup table:
mylevels - data.frame(ID=1:10,code=letters[1:10])
And a set of values (note these do not completely cover the mylevels range):
values - c(1,2,5,5,10)
How do I convert values to a factor object, using the mylevels to
define the
Note that your example may be misleadingly simple, so I made it a bit
more complicated.
The key is ?match
mylevels - data.frame(ID=10:1,code=letters[1:10])
values - c(1,2,5,5,10)
with(mylevels,code[match(values,ID)])
[1] j i f f a
Levels: a b c d e f g h i j
## Note that you may have to take
On Mar 28, 2014, at 3:38 PM, Jonathan Greenberg j...@illinois.edu wrote:
R-helpers:
Hopefully this is an easy one. Given a lookup table:
mylevels - data.frame(ID=1:10,code=letters[1:10])
And a set of values (note these do not completely cover the mylevels range):
values -
5 matches
Mail list logo