我对 R
还不熟悉,目前在读取 .csv
文件并将其转换为有 7
列的 data.frame
过程中遇到了很多麻烦。这是我所做的:
gene_symbols_table <- as.data.frame(read.csv(file="/home/nikita/Desktop
/CElegans_raw_data/gene_symbols_matching.csv", header=TRUE, sep=","))
之后我得到了一个
data.frame
,其 dim = 46761 x 1
,但我需要它是 46761 x 7
。我尝试了以下的 stackoverflow
线程:
但不知何故,在我的情况下什么都没有起作用。 这是表格的样子:
> head(gene_symbols_table, 3)
input.reason.matches.organism.name.primaryIdentifier.symbol.briefDescription.c
lass.secondaryIdentifier
1 WBGene00008675 MATCH 1 Caenorhabditis elegans
WBGene00008675 irld-26 Gene F11A5.7
2 WBGene00008676 MATCH 1 Caenorhabditis elegans
WBGene00008676 oac-15 Gene F11A5.8
3 WBGene00008677 MATCH 1 Caenorhabditis elegans
WBGene00008677 Gene F11A5.9
在Excel中,
.csv
文件看起来像这样:input | reason | matches | organism.name | primaryIdentifier | symbol |
briefDescription
WBGene00008675 | MATCH | 1 | Caenorhabditis elegans WBGene00008675 | irld-26 | ...
...
以下是代码示例:
gene_symbols_table <- read.table(file="/home/nikita/Desktop
/CElegans_raw_data/gene_symbols_matching.csv", header=FALSE, sep=",",
col.names = paste0("V",seq_len(7)), fill = TRUE)
看起来似乎运行正常,但是当我查看dim
时立刻发现它是错误的:20124 x 7
。然后:
V1
1input;reason;matches;organism.name;primaryIdentifier;symbol;briefDescription;class;secondaryIdentifier
2 WBGene00008675;MATCH;1;Caenorhabditis
elegans;WBGene00008675;irld-26;;Gene;F11A5.7
3 WBGene00008676;MATCH;1;Caenorhabditis
elegans;WBGene00008676;oac-15;;Gene;F11A5.8
V2 V3 V4 V5
1
2
3
1
所以,它是错误的。
尝试使用read.table
的其他方法也会出现第二个stackoverflow
线程中指定的错误。
我还尝试将只有一列的data.frame
分成7个部分,但是目前没有成功。
sep=','
更改为sep=';'
时会发生什么? - Natesep = "|"
参数,但这仍然不清楚。此外,read.csv()
的响应是数据框,因此你不需要使用as.data.frame()
。 - Thomas