Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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和R中的多个csv文件中提取单个单元格值_R_Excel_Csv - Fatal编程技术网

从R和R中的多个csv文件中提取单个单元格值

从R和R中的多个csv文件中提取单个单元格值,r,excel,csv,R,Excel,Csv,我有500美元。包含以下数据的文件: 我希望每个csv文件提取一个单元格(例如B4或0.477),并将这些值合并到单个csv中。关于如何轻松做到这一点,有哪些建议?我无法添加评论。所以,我将在这里写下我的评论 由于您的数据非常大,很难单独加载,请尝试以下方法:。这与问题的第一部分类似。对于第二部分,请尝试以下方法: 您可以将数据保存为data.frame(与@Bruno Zamengo的注释一样),然后可以在R中使用select和merge函数。然后,您可以轻松地将它们合并到单个csv文件中。

我有500美元。包含以下数据的文件:


我希望每个csv文件提取一个单元格(例如B4或0.477),并将这些值合并到单个csv中。关于如何轻松做到这一点,有哪些建议?

我无法添加评论。所以,我将在这里写下我的评论

由于您的数据非常大,很难单独加载,请尝试以下方法:。这与问题的第一部分类似。对于第二部分,请尝试以下方法:


您可以将数据保存为
data.frame
(与@Bruno Zamengo的注释一样),然后可以在R中使用
select
merge
函数。然后,您可以轻松地将它们合并到单个
csv
文件中。使用
选择
合并
功能,您可以选择所需的所有值并将其组合。我在我的项目中使用了这个想法。不要忘记使用
lappy

你可以试试这样的东西

all.fi <- list.files("/path/to/csvfiles", pattern=".csv", full.names=TRUE)  # store names of csv files in path as a string vector
library(readr)  # package for read_lines and write_lines
ans <- sapply(all.fi, function(i) { eachline <- read_lines(i, n=4)  # read only the 4th line of the file
                        ans <- unlist(strsplit(eachline, ","))[2]  # split the string on commas, then extract the 2nd element of the resulting vector
                        return(ans) })
write_lines(ans, "/path/to/output.csv")

all.fi每次将一个文件读入一个
data.frame
,访问所需的单元格并将其存储在某处如何?@BrunoZamengo读取所有文件毫无意义请参见
?read.table
。skip和nrows参数将非常有用。您还可以使用
scan
,它接受这两个(nlines而不是nrows)参数,并且进行了一些微调。