R : Map a column to column using key-value list -



R : Map a column to column using key-value list -

in r, want utilize key-value list convert column of keys values. it's similar to: how map column through dictionary in r, want utilize list not data.frame.

i've tried using list , columns:

d = list('a'=1, 'b'=2, 'c'=3) d[c('a', 'a', 'c', 'b')] # want homecoming c(1,1,3,2) doesn't

however, above returns list:

list('a'=1, 'a'=1, 'c'=3, 'b'=2)

unlist useful function in situation

unlist(d[c('a', 'a', 'c', 'b')], use.names=false) #[1] 1 1 3 2

or alternative stack returns 'key/value' columns in 'data.frame'. subsetting values column, get

stack( d[c('a', 'a', 'c', 'b')])[,1] #[1] 1 1 3 2

r list

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -