首页 > 解决方案 > 如何在 r 中创建具有输入/输出的函数?

问题描述

我正在考虑用户通过输入输入的函数,如下所示:

cat("check if the directory is the same of the file")
input <- readline(prompt="Enter with file name in form >file.txt<: ")
output<-readline(prompt="Enter with file output in form >file.dat<: ")

然后,在用户输入 .txt 文件名后,计算向量“sum”,顺便说一句:

column <- read.table(input, header=F)
sum = column * 2

最后生成txt文件输出:

write.table(sum, file=output, row.names=FALSE, col.names=FALSE)

它可以工作,但我不知道如何在一个函数中转换所有这些。

标签: rfunctioninputoutput

解决方案


推荐阅读