r - Convert character list to data frame -
i have data in json trying use in r. problem cannot data in right format.
require(rjsonio) json <- "[{\"id\":\"id1\",\"value\":\"15\"},{\"id\":\"id2\",\"value\":\"10\"}]" example <- fromjson(json) example <- do.call(rbind,example) example <- as.data.frame(example,stringsasfactors=false) > example id value 1 id1 15 2 id2 10 this gets close, cannot numeric column convert numeric. know can convert columns manually, thought data.frame or as.data.frame scanned data , made appropriate class definitions. misunderstood. reading in numerous tables - different - , need have numeric data treated such when it's numeric.
ultimately looking data tables numeric columns when data numeric.
read.table uses type.convert convert data appropriate type. same cleaning step after reading in json data.
sapply(example,class) # id value # "character" "character" example[] <- lapply(example, type.convert, as.is = true) sapply(example, class) # id value # "character" "integer"
Comments
Post a Comment