What does the error “arguments imply differing number of rows: x, y” mean?

前端 未结 3 1246
南方客
南方客 2020-12-05 12:55

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 followi

相关标签:
3条回答
  • 2020-12-05 13:33

    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)
    
    0 讨论(0)
  • 2020-12-05 13:46

    I had the same error message so I went googling a bit I managed to fix it with the following code.

    df<-data.frame(words = unlist(words))
    

    words is a character list.

    This just in case somebody else needs the output to be a data frame.

    0 讨论(0)
  • 2020-12-05 13:46

    Though this isn't a DIRECT answer to your question, I just encountered a similar problem, and thought I'd mentioned it:

    I had an instance where it was instantiating a new (no doubt very inefficent) record for data.frame (a result of recursive searching) and it was giving me the same error.

    I had this:

    return(
      data.frame(
        user_id = gift$email,
        sourced_from_agent_id = gift$source,
        method_used = method,
        given_to = gift$account,
        recurring_subscription_id = NULL,
        notes = notes,
        stringsAsFactors = FALSE
      )
    )
    

    turns out... it was the = NULL. When I switched to = NA, it worked fine. Just in case anyone else with a similar problem hits THIS post as I did.

    0 讨论(0)
提交回复
热议问题