使用R在csv文件中跳过注释行 [英] Skip comment line in csv file using R

查看:1154
本文介绍了使用R在csv文件中跳过注释行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个csv文件,看起来像这样 -

I have a csv file which looks like this-

    #this is a dataset
    #this contains rows and columns

   ID     value1  value2   value3
   AA       5       6        5
   BB       8       2        9
   CC       3       5        2

我想读取除了那些注释行之外的csv文件。有可能读取提到,当它是'#'跳过这些行。但这里的问题是有一个空行后的注释,也为我的不同的csv文件,它可以是各种数量的注释行。但主头将

I want read the csv file excluding those comment lines. It is possible to read mentioning that when it is '#' skip those line.But here the problem is there is an empty line after comments and also for my different csv file it can be various numbers of comment lines.But the main header will always start with "ID" from where i want to read the csv.

可以指定ID是从哪里读取的?如果是,那么请举个例子。

It is possible to specify somehow that when it is ID read from there? if yes then please give an example.

提前感谢!

推荐答案

使用< =https://stat.ethz.ch/R-manual/R-devel/library/utils/html/read.table.html> comment.char 选项:

read.delim('filename', comment.char = '#')

空行将默认自动跳过( blank.lines.skip = TRUE )。您还可以通过 skip = number 指定要跳过的固定行数。然而,它不可能指定它应该开始读取从'ID'开始的一个给定的行(但是像我说的没有必要在这里)。

Empty lines will be skipped automatically by default (blank.lines.skip = TRUE). You can also specify a fixed number of lines to skip via skip = number. However, it’s not possible to specify that it should start reading at a given line starting with 'ID' (but like I’ve said it’s not necessary here).

这篇关于使用R在csv文件中跳过注释行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆