writing a R hashtable in to a CSV file? -


what trying implement write r hashtable csv file excel ( column formatted file- keys in first column , values in second). please consider example. (the hash table created hash package)

<hash> containing 5 key-value pair(s).   1 : 4   2 : null   3 : null   4 : 3 1   5 : 1 4 

when use

write.csv(hash, file = "hash.csv",row.names=false) 

it gives me error

error in as.data.frame.default(x[[i]], optional = true) :    cannot coerce class "structure("hash", package = "hash")" data.frame 

so try create dataframe each key , values , bind them:

a<-as.data.frame(keys(hash)) b<-as.data.frame(values(hash)) error in data.frame(`1` = "4", `2` = null, `3` = null, `4` = c("3", "1" :    arguments imply differing number of rows: 1, 0, 2 

then create list , vector :

a<-keys(hash) b<-values(hash) d<-cbind(a,b) f<-as.data.frame(d)      b 1 1    4 2 2 null 3 3 null 4 4 3, 1 5 5 1, 4 

but when try write it:

write.csv(f, file = "hash.csv",row.names=false) error in .external2(c_writetable, x, file, nrow(x), p, rnames, sep, eol,  :    unimplemented type 'list' in 'encodeelement' 

so there other way or way fix error ? thank in advance.

this somehow me. not yet answer of question looking better solution.

a<-keys(hash)   b<-values(hash)   d<-cbind(a,b)   l<-as.data.frame(d)   l.df <- data.frame(lapply(l, as.character), stringsasfactors=false)   write.csv(f.df, file ="file.csv",row.names=false)     csv file format     # b     # 1 4     # 2 null     # 3 null     # 4 c("3", "1")     # 5 c("1", "4") 

Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -