错误“参数表示不同的行数:x,y"是什么意思?意思是? [英] What does the error "arguments imply differing number of rows: x, y" mean?
问题描述
我正在尝试根据csv文件的元素创建一个绘图,如下所示:
I'm trying to create a plot from elements of csv file which looks like this:
h1,h2,h3,h4
a,1,0,1,0
b,1,1,0,1
c,0,0,1,0
我尝试了以下代码,但收到一条错误消息
I tried the following code but am receiving an error saying
Error in data.frame(id = varieties, attr(mat, "row.names"), check.rows = FALSE) :
arguments imply differing number of rows: 8, 20
我的样本数据有8列和20行(不包括标题和行名).我尝试在线查找并尝试实施一些修复程序,但问题仍然存在.我真的很感谢您的帮助.
my sample data has 8 columns and 20 rows (excluding header and row names). I tried to look up online and tried to implement a few fixes but the issue still persists. I'd really appreciate any help.
mat <- read.csv("trial.csv", header=T, row.names=1)
varieties = names(mat)
df <- data.frame(id=varieties,attr(mat, "row.names"), check.rows= FALSE)
推荐答案
您的data.frame mat
是矩形的(n_rows!= n_cols).
Your data.frame mat
is rectangular (n_rows!= n_cols).
因此,您不能在列名和行名中加上data.frame
,因为data.frame中的每一列都必须具有相同的长度.
Therefore, you cannot make a data.frame
out of the column- and rownames, because each column in a data.frame must be the same length.
也许这足以满足您的需求:
Maybe this suffices your needs:
require(reshape2)
mat$id <- rownames(mat)
melt(mat)
这篇关于错误“参数表示不同的行数:x,y"是什么意思?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!