繁体   English   中英

使用R中的函数加载.txt文件

[英]Loading .txt files using a function in R

以下代码有效:

Name<-"s1521r0000_rd2.txt"  
OneFile<-read.table(file=Name, sep="", skip=35, fill=TRUE )

但是,我试图编写一个函数来加载一个.txt文件,以便可以加载所需的任何.txt文件。 我写了下面的功能不起作用:

ReadOneFile<-function(Name="s1521r0000_rd2.txt"){  
 OneFile<-read.table(file=Name, sep="", skip=35, fill=TRUE )  
}  

如果您能帮助我,那就太好了。

您需要将函数中的文件return()到对象中。 例如:

func.readonefile <- function(Name) {
    thefile <- read.table(file=Name,sep="",skip=35,fill=TRUE)
    return(thefile)
}
a_file <- func.readonefile(Name="s1521r0000_rd2.txt")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM