r - Using rbind.fill does not fill the correct value -


i don’t understand how rbind.fill works, guess. have data frame called main.df:

     tlt pcy shy vti tip vnq vwo rwx vea dbc gld pct   0   0   0   0   0   0   0   0   0   0   0 

i want bind following different-sized data frame named p.df it:

          vwo       vea       vti pct 0.3333333 0.3333333 0.3333333 

when execute rbind.fill(main.df, p.df) get:

  tlt pcy shy vti tip vnq vwo rwx vea dbc gld 1   0   0   0   0   0   0   0   0   0   0   0 2  na  na  na   1  na  na   1  na   1  na  na 

which not want. expected get:

  tlt pcy shy vti     tip vnq  vwo     rwx vea    dbc gld 1   0   0   0   0       0   0    0       0   0     0   0  2  na  na  na   0.333   na  na   0.333  na  0.333  na  na 

how do this? dput of objects below.

main.df <- structure(list(   tlt = 0, pcy = 0, shy = 0, vti = 0, tip = 0, vnq = 0, vwo = 0, rwx = 0, vea = 0, dbc = 0, gld = 0),   .names = c("tlt", "pcy", "shy", "vti", "tip", "vnq", "vwo", "rwx", "vea", "dbc", "gld"),   row.names = "pct", class = "data.frame")  p.df <- structure(list(   vwo = structure(1l, .names = "pct", .label = c("0.3333333", "vwo"), class = "factor"),   vea = structure(1l, .names = "pct", .label = c("0.3333333", "vea"), class = "factor"),   vti = structure(1l, .names = "pct", .label = c("0.3333333", "vti"), class = "factor")),   .names = c("vwo", "vea", "vti"), row.names = "pct", class = "data.frame") 

it if provided reproducible example using dput(main.df) , dput(p.df), appears 1 or both of objects contain factor vectors, not numeric vectors. need convert them.

main.df[] <- lapply(main.df, function(f) as.numeric(levels(f))[f]) p.df[] <- lapply(p.df, function(f) as.numeric(levels(f))[f]) 

see how convert factor integer\numeric without loss of information details.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -