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

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -