简体   繁体   English

R:对于每个不同的数据行如何读取特定文件?

[英]R: for every different line of data how to read a specific file?

I am training Neural network with R. I am using .rds files. 我正在用R.训练神经网络。我正在使用.rds文件。 Now I have 7000 of these files. 现在我有7000个这样的文件。 They all have the name: model_nn_X_Y.rds. 它们都有名称:model_nn_X_Y.rds。 X and Y are the numbers and they are different for every .rds. X和Y是数字,它们对于每个.rds都不同。 Furthermore, I have data with columns: Xp Yp H WX WY, also there are 7000 rows. 此外,我有列数据:Xp Yp H WX WY,也有7000行。 WX WY I am using as attributes for prognosis. WX WY我用作预后的属性。 Prognosis I am doing for every different point X Y. So How I can pick the right file model_nn_X_Y.rds for the right XY value. 预测我正在为每个不同的点X Y做。所以我如何为正确的XY值选择正确的文件model_nn_X_Y.rds。

Files: model_nn_20.992_54.0093.rds 文件:model_nn_20.992_54.0093.rds

model_nn_21.026_54.0277.rds model_nn_21.026_54.0277.rds

Data: 数据:

"Xp" "Yp" "depth" "t" "dir" "hs" "xw" "yw" “Xp”“Yp”“depth”“t”“dir”“hs”“xw”“yw”

20.992 54.0093 0.7389 1.1798 96.725 0.13842 -0.0000 6.0000 20.992 54.0093 0.7389 1.1798 96.725 0.13842 -0.0000 6.0000

21.009 54.0093 0.9947 1.2053 93.147 0.14697 -0.0000 6.0000 21.009 54.0093 0.9947 1.2053 93.147 0.14697 -0.0000 6.0000

21.026 54.0093 0.9947 1.2239 91.504 0.14636 -0.0000 6.0000 21.026 54.0093 0.9947 1.2239 91.504 0.14636 -0.0000 6.0000

21.043 54.0093 0.7809 1.2240 90.149 0.14293 -0.0000 6.0000 21.043 54.0093 0.7809 1.2240 90.149 0.14293 -0.0000 6.0000

Now I have done this using bash. 现在我用bash做了这个。 For 7000 points to work, it takes a very long time because it goes in and out from R to bash. 要使7000点工作,需要很长时间,因为它从R进出bash。

filenames <- gsub("\\.rds$","", list.files(pattern="model_nn+.*rds")) this line puts into R all .rds files from the directory filenames < - gsub(“\\。rds $”,“”,list.files(pattern =“model_nn +。* rds”))此行将R目录中的所有.rds文件放入目录中

If you add a column with your corresponding desired file to read in for each row, you could use map() something like this: map(file_path, readRDS). 如果添加一个包含相应所需文件的列以便为每行读入,则可以使用map(),如下所示:map(file_path,readRDS)。 Just vectorize the file paths and any other parameters you need and use map. 只需向量化文件路径和您需要的任何其他参数并使用map。

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

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