0
map 데이터 목록을 keys and values으로 변환하려고합니다. 하지만 그것을 변환하는 문제에 직면, 나는 아래의 코드로 시도했지만 내 요구 사항을 만족하지 않습니다. I는 상기 코드R : 데이터 프레임의 키 값 쌍에 출력을 생성 할 수 없습니다.
> df <- data.frame(sec = c('15:31:36',"15:31:37",'15:31:37','15:31:37','15:31:38','15:31:39'),
label = c("Choose to and fro flights","Choose to and fro flights","Details","Details","Details","Details"),
responseCode = c(200,200,200,'Non HTTP response code: org.apache.http.NoHttpResponseException','200','200'),
Counting = c(9,1,2,2,5,1))
> purList1 <- lapply(split(df, df$label), function(x) split(x, x$responseCode,drop = T))
> output <- toJSON(
list(ResponseCode =
lapply(names(purList1),function(x){
ss = purList1[[x]]
tt = lapply(names(ss),function(y){
items = ss[[y]][c("sec","Counting")]
sub = data.frame(R_C_seconds = as.vector(items$sec),
R_C_Count = as.vector(items$Counting)
)
c(as.vector(unlist(data.frame(y))), as.vector(sub))
})
c(as.vector(x), as.vector(tt))
})
)
,pretty = T)
Genereated Optput 아래의 화상 표시 등의 데이터를 필요
{
"ResponseCode": [
[
["Choose to and fro flights"],
{
"1": ["200"],
"R_C_seconds": ["15:31:36", "15:31:37"],
"R_C_Count": [9, 1]
}
],
[
["Details"],
{
"1": ["200"],
"R_C_seconds": ["15:31:37", "15:31:38", "15:31:39"],
"R_C_Count": [2, 5, 1]
},
{
"1": ["Non HTTP response code: org.apache.http.NoHttpResponseException"],
"R_C_seconds": ["15:31:37"],
"R_C_Count": [2]
}
]
]
}
가
하지만 스피 에서 아래 지정된 JSON 출력을 제외한 형식 키 값 쌍.
당신이 @yutannihilation 감사드립니다. – user7462639
처음에는'jsonlite :: toJSON (purList1, dataframe = "column", pretty = TRUE)'을 시도했지만 매개 변수'dataframe'을 사용하지 않았습니다. 그래서 길이 코드를 작성하고 있습니다. 그리고 만약 위의 코드'jsonlite :: toJSON (purList1, dataframe = "column", pretty = TRUE)을 사용한다면'나는 모든 열을 얻는다. 암호. 다시 한번 감사드립니다. – user7462639
나는 길다는 것이 합리적이다. 세부 사항 주셔서 감사합니다 :) – yutannihilation