r - 从 R 中的列创建循环以进行代码替换
问题描述
我想复制并粘贴几次,但不是示例中包含的“代码”,而是包含存储在 xlsx 数据集的列上的值。这是我的起点(R 脚本):
r <- POST(paste(url_base,service,method,sep="/"),
body = paste("{'entity':'sigpac', code: 'imported_file$code' }",sep=""),
add_headers(.headers = c("Content-Type"="application/json","authorization"=token)))
因此,在“imported_file$code”中,我想定义循环以重复除列的不同行之外的所有内容。
例如,这将是一个可悲的结果。
[{
"entity":"sigpac",
"code":"18188-7-81-11-1",
"status":"ON"
},{
"entity":"sigpac",
"code":"18142-20-237-0-1",
"status":"ON"
},{
"entity":"sigpac",
"code":"181232-20-237-0-1",
"status":"ON"}
},{
"entity":"sigpac",
"code":"1315432-20-237-0-1",
"status":"ON"}
(ETC...)
如您所见,只有参数code
是我要更改的参数。
为了澄清,我重新提出了这个问题。感谢我学习的帮助!
解决方案
这个怎么样?
imported_file <- data.frame(code = c("18188-7-81-11-1",
"18142-20-237-0-1",
"181232-20-237-0-1",
"1315432-20-237-0-1"))
mystring <- paste('{\n\t"entity":"sigpac",\n\t"code":"', imported_file$code, '",\n\t"status":"ON"\n}',sep="",collapse=",")
cat(mystring)
推荐阅读
- javascript - 那里有一个 y 轴数据点,但每周图表中缺少 x 轴数据点
- docker - 如何清除与(kubernetes)k8s相关的容器?
- serial-port - 逆向工程串行协议
- node.js - 如何获取渲染的 html 的屏幕截图来创建 png?
- javascript - 运行 google 电子表格的 javascript 代码时,显示“TypeError: Cannot read property 'createEvent' of null”消息
- visual-studio - 当 ItemsSource 加载大数据时,Xamarin.Forms 会阻止 UI
- haskell - 模式绑定:为什么允许递归模式?
- vb6 - 在 Tally ERP9 响应 xml 中
- flutter - Flutter - 在 Flutter 导航堆栈中获取 TopView 的名称
- excel - 从 Excel 工作表中删除公式