I need to create and R function that would take a data frame and column names as arguments (there should be at least two column names in the argument list and maybe more). Then given the data frame, I need to create a json formatted output based the given column names. For example,
this is my df:
structure(list(DateTime = structure(1:8, .Label = c("8/24/2014 15:20",
"8/24/2014 15:55", "8/24/2014 16:04", "8/24/2014 16:18", "8/24/2014 16:27",
"8/24/2014 16:42", "8/24/2014 16:56", "8/24/2014 17:10"), class = "factor"),
Server1 = c(6.09, 4.54, 5.03, 4.93, 6.27, 4.59, 5.91, 4.53
), Server2 = c(5.7, 4.38, 4.52, 4.61, 4.18, 4.61, 4.37, 4.3
), Server3 = c(5.21, 5.33, 4.92, 5.56, 5.62, 6.73, 4.76,
4.59)), .Names = c("DateTime", "Server1", "Server2", "Server3"
), class = "data.frame", row.names = c(NA, -8L))
I need this function to return this output:
[{"name":"Server1","data":[[18/24/2014 15:20,6.09],[8/24/2014 15:55,4.54],[8/24/2014 16:04,5.03]]},
{"name":"Server2","data":[[18/24/2014 15:20,7.7],[8/24/2014 15:55,4.38],[8/24/2014 16:04,4.52]]},
{"name":"Server3","data":[[18/24/2014 15:20,5.21],[8/24/2014 15:55,5.33],[8/24/2014 16:04,4.92]]}]
Any ideas how I would start with this?