过滤 CSV 文件,该文件的列名称上方有文本,且过滤过程后必须维护这些文本

问题描述 投票:0回答:1

我处理数百个 CSV 文件,这些文件在多个列标题上方有三行文本。

这些文件最大可达 300MB。它们需要被过滤到 < 1/3 the size in local preprocessing, before the result is pushed to a server for processing. Filtering is fine when the three lines are removed on upload.

A <- read_csv_arrow( p , as_data_frame = TRUE, skip = 3) 

但问题是在过滤后的相同状态下替换文本(前三行),因为该信息与后续处理相关。

我尝试了多种方法,将文本隔离为对象,然后在过滤后使用 cat() 替换它,但该过程必须以 CSV 结束,但我没有成功实现。

r csv filter
1个回答
0
投票

使用

write.table
两次。

假设您已将前三行存储到名为

text
的对象中。 将其写入没有行或列标题的 csv 文件:

write.table(text, file="filename.csv", col.names=FALSE, row.names=FALSE, sep=",")

然后将名为

mydata
的数据框附加到此 csv 文件中。

write.table(mydata, file="filename.csv", sep=",", append=TRUE)
© www.soinside.com 2019 - 2024. All rights reserved.