r - Can't write data frame to database -
i can't create code example because i'm not quite sure problem , actual problem rather involved. said seems kind of generic problem maybe somebody's seen before.
basically i'm constructing 3 different dataframes , rbinding them together, expected smooth sailing when try write merged frame db error:
error in .external2(c_writetable, x, file, nrow(x), p, rnames, sep, eol, : unimplemented type 'list' in 'encodeelement'
i've tried manually coercing them using as.data.frame() before , after rbinds , returned object (the same 1 fails write above error message) exists in environment class data.frame why dbwritetable not seem have got memo?
sorry, i'm connecting mysql db using rmysql. problem think little closer , try explain myself columns of data frame lists (of same length), sorta makes sense of error. i'd think (or think anyways) call as.data.frame() take care of guess not?
a portion of str() since it's long looks like:
.. [list output truncated] $ stcong :list of 29809 ..$ : int 3 ..$ : int 8 ..$ : int 4 ..$ : int 2
i guess i'm wondering if there's easy way force coercion?
hard sure, since provided little concrete information, 1 way convert list column atomic vector column:
> d <- data.frame(x = 1:5) > d$y <- as.list(letters[1:5]) > str(d) 'data.frame': 5 obs. of 2 variables: $ x: int 1 2 3 4 5 $ y:list of 5 ..$ : chr "a" ..$ : chr "b" ..$ : chr "c" ..$ : chr "d" ..$ : chr "e" > d$y <- unlist(d$y) > str(d) 'data.frame': 5 obs. of 2 variables: $ x: int 1 2 3 4 5 $ y: chr "a" "b" "c" "d" ...
this assumes each element of list column length 1 vector. if aren't, things more complicated, , you'd need rethink data structure anyhow.
Comments
Post a Comment