我使用这样的函数toJSON
来创建一个json:
data<-toJSON(list("tablename"= unbox("test.csv"),
"header" = header_df,
"data" = test1
))
结果如下:
数据
{"tablename":"test.csv","header":["PassengerId","Pclass","Name","Sex","Age","SibSp","Parch","Ticket","Fare","Cabin","Embarked"],"data":[["892","3","Kelly, Mr. James","male","34.5","0","0","330911","7.8292","","Q"]]}
问题是它为PassengerID
和Age
数字添加了双引号。如果我手动将 JSON 修改为:
data<-'{"tablename":"test.csv","header":["PassengerId","Pclass","Name","Sex","Age","SibSp","Parch","Ticket","Fare","Cabin","Embarked"],"data":[[892,"3","Kelly, Mr. James","male",34.5,"0","0","330911","7.8292","","Q"]]}'
然后它工作正常。创建 JSON 时如何删除 JSON 中某些元素的双引号?
您可以在此处找到输入数据:
嗨,你可以在这里找到它链接我使用以下加载它
test <- read.csv("~/Titanic R/test.csv")
header_df<-names(test)
test<-test[1,]
test1<-as.matrix(test)