如何将CSV文件转换为R中的.txt文件(How to convert CSV file to .txt file in R)
给定一个巨大的CSV文件,我想只读取它的前2000行,并将其保存为.txt文件。
data<-read.csv("myfile", header=T, sep=",", nrow=2000)Given a huge CSV file, I want to read just the first 2000 lines of it and save it as a .txt file.
data<-read.csv("myfile", header=T, sep=",", nrow=2000)最满意答案
在Linux / MacOS下,您可以使用head来执行此操作而无需读取文件:
head -n 2001 source_file > target_file这假设有一个头,因此文件中的前2001行放在target_file 。 在Windows下,您可以通过安装Cygwin或MinGW 。
为了解决你在R中的问题,你已经在R中有了内容。只需使用write.csv将数据写入文件即可。
Under Linux/MacOS you can use head to do this without having to read the file:
head -n 2001 source_file > target_fileThis assumes that there is a header, therefore the first 2001 rows in the file are put in target_file. Under Windows you can get this working by installing Cygwin or MinGW.
For solving your problem in R, you already have the content in R. Just use write.csv to write the data to a file.
更多推荐
发布评论