参数意味着不同的行数:8,20 [英] arguments imply differing number of rows: 8, 20

查看:3164
本文介绍了参数意味着不同的行数:8,20的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从csv文件的元素创建一个情节,如下所示:

  h1,h2,h3 ,h4 
a,1,0,1,0
b,1,1,0,1
c,0,0,1,0

我试过下面的代码,但收到一个错误,说:

 错误在data.frame(id =品种,attr(mat,row.names),check.rows = FALSE):
参数意味着不同的行数:8,20

我的示例数据有8列20行(不包括标题和行名)。我试图在网上查找,并试图实施一些修复,但问题仍然存在。我真的很感激任何帮助。

  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)。



因此,您不能在列中创建 data.frame



也许这足以满足您的需求:

  require(reshape2)
mat $ id < - rownames(mat)
melt(mat)
pre>

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 

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)

解决方案

Your data.frame mat is rectangular (n_rows!= n_cols).

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)

这篇关于参数意味着不同的行数:8,20的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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