0

here is my context-:

 context<- '[["2014-01-01","192.168.1.1",41],["2014-01-02","192.168.1.1",30],["2014-01-03","192.168.1.1",25],["2014-01-04","192.168.1.1",0],["2014-01-05","192.168.1.1",0],["2014-01-06","192.168.1.1",30],["2014-01-07","192.168.1.1",40],["2014-01-08","192.168.1.1",41],["2014-01-09","192.168.1.1",30],["2014-01-10","192.168.1.1",25],["2014-01-11","192.168.1.1",0],["2014-01-12","192.168.1.1",0],["2014-01-13","192.168.1.1",30],["2014-01-14","192.168.1.1",40],["2014-01-15","192.168.1.1",40],["2014-01-16","192.168.1.1",30],["2014-01-17","192.168.1.1",25],["2014-01-18","192.168.1.1",0],["2014-01-19","192.168.1.1",0],["2014-01-20","192.168.1.1",30],["2014-01-21","192.168.1.1",40],["2014-01-22","192.168.1.1",40],["2014-01-23","192.168.1.1",30],["2014-01-24","192.168.1.1",25],["2014-01-25","192.168.1.1",0],["2014-01-26","192.168.1.1",0],["2014-01-27","192.168.1.1",30],["2014-01-28","192.168.1.1",40],["2014-01-29","192.168.1.1",41],["2014-01-30","192.168.1.1",30],["2014-01-31","192.168.1.1",25],["2014-02-01","192.168.1.1",0],["2014-02-02","192.168.1.1",0],["2014-02-03","192.168.1.1",30],["2014-02-04","192.168.1.1",40],["2014-02-05","192.168.1.1",40],["2014-02-06","192.168.1.1",30],["2014-02-07","192.168.1.1",25],["2014-02-08","192.168.1.1",0],["2014-02-09","192.168.1.1",0],["2014-02-10","192.168.1.1",30],["2014-02-11","192.168.1.1",40],["2014-02-12","192.168.1.1",40]]'

help me to convert this in dataframe i did this

    > data_context<-fromJSON(context)
    > data <-
      data.frame(
       "timeslice" = data_context[, 1],
      "host" = data_context[, 2],
     "metric" = as.numeric(data_context[, 3])
     )

it does not work

1 Answer 1

2

You could do something like the following:

library(rjson)
step1 <- fromJSON(context) 
setNames(
  data.frame(do.call(rbind, step1)), 
  c("timeslice", "host", "metric")
)

    timeslice        host metric
1  2014-01-01 192.168.1.1     41
2  2014-01-02 192.168.1.1     30
3  2014-01-03 192.168.1.1     25
4  2014-01-04 192.168.1.1      0
5  2014-01-05 192.168.1.1      0
6  2014-01-06 192.168.1.1     30
..
Sign up to request clarification or add additional context in comments.

2 Comments

BRO , you are simply awesome
do one more thing , please change name to which i mentioned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.