I have a simple data.frame df
a b c d
1 5 A E
2 4 B F
3 3 C G
4 2 D H
5 1 E J
Let's say I want to write it in JSON format:
jsonlite::toJSON(df[1,])
returns:
[{"a":1,"b":10,"c":"A","d":"J"}]
However,
apply(df[1,], 1, jsonlite::toJSON)
returns:
"[\"1\",\"10\",\"A\",\"J\"]"
Where did the names of my variables go? How can I get them back?
Thanks,
Carlos