Convert R data.frame to JSON.
Created
October 9, 2013 16:53
-
-
Save jfreels/6904461 to your computer and use it in GitHub Desktop.
Convert R data.frame to JSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(RJSONIO) | |
require(plyr) | |
json<-function(data.frame,sink=FALSE) { | |
modified<-list( | |
keys = colnames(data.frame), | |
values = unname(alply(data.frame,1,identity)) | |
) | |
if(sink!=FALSE) { | |
sink(sink) | |
cat(toJSON(modified,pretty=TRUE)) | |
sink() | |
} | |
if(sink==FALSE) { | |
cat(toJSON(modified,pretty=TRUE)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you expand this code, i mean how does it print your dataframe??