Niek de Klein
Niek de Klein

Reputation: 8834

'x' must be numeric for histogram of row of dataframe

I have a dataframe df for which I want to make a histogram of some of the rows. I can select the rows with df["row1",] and I get (showing 4 of 114 columns):

     X3432_re  X232_fa  X212_lf  X634_fv
row1 5.1       4.3      3.7      3.7

However, when I try hist(df["row1",]) I get the 'x' must be numeric error. I tried hist(as.vector(df["row1",])) but got the same problem. How can I make a histogram of a row of a dataframe?

Upvotes: 3

Views: 1313

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

df["row1",] will still be a data.frame so hist(df["row1",]) won't work by default (as hist requires a vector).

Now assuming all your columns can be coerced to numeric I suspect this will work since a numeric atomic vector will be created:

hist(as.numeric(df["row1",]))

Upvotes: 5

Related Questions