Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R、Ubuntu14.04 LTS、R版本3.2.4修订版中打开特定目录中的txt文件时出现的问题_R - Fatal编程技术网

在R、Ubuntu14.04 LTS、R版本3.2.4修订版中打开特定目录中的txt文件时出现的问题

在R、Ubuntu14.04 LTS、R版本3.2.4修订版中打开特定目录中的txt文件时出现的问题,r,R,我在试图通过read.table读取文件夹中的txt文件时遇到了一个非常奇怪的问题。它可以识别文件的存在(我通过print方法调试),但无法将文件读入表中。 有人知道出了什么问题吗? 我已经看过了其他相关的话题,但是我没有找到适合我问题的答案。 这是我的密码: path1 = "/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/" out.file<-"

我在试图通过read.table读取文件夹中的txt文件时遇到了一个非常奇怪的问题。它可以识别文件的存在(我通过print方法调试),但无法将文件读入表中。 有人知道出了什么问题吗? 我已经看过了其他相关的话题,但是我没有找到适合我问题的答案。 这是我的密码:

path1 = "/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/"
out.file<-""
file.names1 <- dir(path1, pattern =".txt")
listofdfs<-list()
for(i in 1:length(file.names1))
{
     print(file.names1[i])
     file <- read.table(file.names1[i])
     df<-data.frame(as.numeric(file[[1]]),as.numeric(file[[2]]),as.numeric(file[[3]]),as.numeric(file[[4]]))
     listofdfs[[i]]<-df
     #write.table(listofdfs[[i]],file=paste0("outliers_",file.names1[i],quote=F,row.names = F, col.names = F))
}

它必须是文件路径。该目录不是工作目录,
dir()
只返回文件名,而不是完整路径。使用
full.names
参数应该可以解决这个问题。比如说

dir("~/Desktop", full.names = T)

它必须是文件路径。该目录不是工作目录,
dir()
只返回文件名,而不是完整路径。使用
full.names
参数应该可以解决这个问题。比如说

dir("~/Desktop", full.names = T)

错误是因为您试图读取的文件不在当前目录中。 R始终尝试从当前目录读取文件

要了解当前目录,请尝试:

getwd()
它与您的
路径1
不同

如@R.S.所述,请使用全名。请尝试以下内容:

path1 = "/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/"
out.file<-""
file.names1 <- dir(path1, pattern =".txt",full.names = T)
path1=“/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/”

out.file错误是因为您试图读取的文件不在当前目录中。 R始终尝试从当前目录读取文件

要了解当前目录,请尝试:

getwd()
它与您的
路径1
不同

如@R.S.所述,请使用全名。请尝试以下内容:

path1 = "/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/"
out.file<-""
file.names1 <- dir(path1, pattern =".txt",full.names = T)
path1=“/home/yoda/Desktop/thesis/TullyFisher/Galac.RC_Dwarfs/TFRCHI/bins_29_04/7bins_TF/datasets/TFR/”
out.file