简体   繁体   English

读取选项卡分隔文件R中的问题

[英]trouble in read tab delimited file R

I am trying to read a tab delimited file that looks like this: 我试图读取一个如下所示的制表符分隔文件: 在此输入图像描述

I am using the read.table for this propose but I am not able to read the file. 我正在使用read.table进行此建议,但我无法读取该文件。

table<- read.table("/Users/Desktop/R-test/HumanHT-12_V4_0_R2_15002873_B.txt",
                   header =FALSE, sep = "\t", 
                   comment.char="#", check.names=FALSE)

When I run the code I have this error: 当我运行代码时,我有这个错误:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
  line 1 did not have 2 elements 

What am I doing wrong while reading the table? 读桌子时我做错了什么? I am not so familiarized with R, so any help would be really useful. 我对R不熟悉,所以任何帮助都会非常有用。

I am very familiar with this type of file: It is a GEO platform data for Microarray analysis. 我对这种类型的文件非常熟悉:它是用于微阵列分析的GEO平台数据。 As baptiste proposed above, the best way is to skip the first few lines by skip=9 . 正如上面提到的baptiste,最好的方法是跳过前几行skip=9 You may replace read.table(...,sep="\\t") with just read.delim(...) . 您可以用read.delim(...)替换read.table(...,sep="\\t") read.delim(...) Then you will have your table with suitable column names - please note that the column names should be in the 1st line. 然后,您的表格将包含合适的列名称 - 请注意列名称应位于第1行。

Then if you are really interested in the first 9 lines you may read them by readLines(...) command and paste the data to your table by acting like this: 然后,如果您对前9行感兴趣,可以通过readLines(...)命令读取它们,并将数据粘贴到表中,方法如下:

foo = read.delim(...)
bar = readLines(...)
baz = list(foo, bar)

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

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