我正在尝试将这段R代码转换为bash:
year <- 2010
emmissions <- paste("Emmision table from ",year, sep="")
em_table <- read.table(emmissions, head=F, as.is=T)
for (i in 1:nrow(em_table)) {
print(em_table[i,1])
}
但是无法弄清楚如何翻译粘贴函数以将字符串与变量连接在一起。预期的结果是将该脚本翻译成bash代码。
也许在您的for循环中使用echo "Emmision table from ${year}"
,如下所示:
for var in 2001 2003 2004;
do
echo "Emission table ${var}"
done
根据OP的请求进行了更新:
对于在bash中生成序列,可以执行以下操作:for i in {1..5}
表示1到5的序列,或{0..20..4}
表示步长从0到20的4]
假设采用类似结构的列,则可以执行以下操作:假设一个表中有两列保存在文本文件中
col1 col2
1 2
3 4
5 6
while read col1 col2
do
echo "Col1 : $col1"
echo "Col2 : $col2"
done < table.txt