包含R列信息的bash参数,从字符到数字

包含R列信息的bash参数,从字符到数字,r,bash,R,Bash,尝试将列坐标从bash传递到R脚本。例如: Rscript script.R Input.table "29:37,40:48" "11:19" Output.file 然后我有剧本 #!/usr/bin/env Rscript args <- commandArgs(trailingOnly = TRUE) a <- read.table(args[1], header=T, row.names=1) locg1 <- c(args[2]) locg2 <- c

尝试将列坐标从bash传递到R脚本。例如:

Rscript script.R Input.table "29:37,40:48" "11:19" Output.file
然后我有剧本

#!/usr/bin/env Rscript

args <- commandArgs(trailingOnly = TRUE)

a <- read.table(args[1], header=T, row.names=1)

locg1 <- c(args[2])
locg2 <- c(args[3])
meangroup1 <- mean(a[,locg1])
meangroup2 <- mean(a[,locg2])
#/usr/bin/env Rscript

args我不擅长使用命令行中的
Rscript
调用R脚本,但鉴于此简化版本:

Rscript script.R "29:37,40:48"
我们可以尝试使用
strsplit
来分隔这两次:

times <- strsplit(args[1], ",")[[1]]
locg1 <- times[1]
locg2 <- times[2]

谢谢。我发现有必要添加[[1]],比如times@AdrianP。对不起,事实上我是在演示中这样做的,但它从未被复制过。