下面是一個示例,使用與您的樣本數據框類似的示例。
library(jsonlite)
# Create sample data frame
> d1 <- data.frame(id=c(1,2),B=c(0,1), C=c(1,0), D=c(0,0))
# Add a column concatenating B,C and D
> d1$x <- with(d1, paste(B, C, D,sep=","))
> d1
id B C D x
1 1 0 1 0 0,1,0
2 2 1 0 0 1,0,0
>
# Add opening and closing square brackets
> d1$x <- with(d1, paste("[",x,sep = ""))
> d1
id B C D x
1 1 0 1 0 [0,1,0
2 2 1 0 0 [1,0,0
> d1$x <- with(d1, paste(x,"]",sep = ""))
> d1
id B C D x
1 1 0 1 0 [0,1,0]
2 2 1 0 0 [1,0,0]
>
# Subset the columns we need
> d2 <- d1[,c("id","x")]
> d2
id x
1 1 [0,1,0]
2 2 [1,0,0]
# create JSON
> x <- toJSON(d2)
> x
[{"id":1,"x":"[0,1,0]"},{"id":2,"x":"[1,0,0]"}]
請'輸入'您的數據的一部分,不要鏈接到數據...尤其是如果這些鏈接與圖片... – SabDeM