[R] need help with unlist(), losing NULL values
    dinesh 
    dinesh.k.somani at gmail.com
       
    Tue Jun 19 12:57:33 CEST 2012
    
    
  
Hi,
I have a very rudimentary kind of question on using unlist(). I am 
parsing a bunch of JSON text using rjson package. Some data elements in 
a dictionary happen to be null which rjson parses correctly.
 > fromJSON(json_str='{"query":{"A":10, "B":null, "C":"hello"}, 
"query":{"A":20, "B":null, "C":"hello again"}}')
$query
$query$A
[1] 10
$query$B
NULL
$query$C
[1] "hello"
$query
$query$A
[1] 20
$query$B
NULL
$query$C
[1] "hello again"
I need to view this as a matrix, for example as
matrix(unlist(fromJSON(json_str='{"query":{"A":10, "B":null, 
"C":"hello"}, "query":{"A":20, "B":null, "C":"hello again"}}')), nr=2)
BUT I lose column "B". It gets worse if some of the B's are not null, 
and if I were really unlucky then matrix() would not fail but data will 
be messed up.
My question is - is there a different way of using unlist() that I am 
missing? Is there a better way of getting this data in a rectangular format?
-- 
Thanks and regards,
Dinesh
    
    
More information about the R-help
mailing list