简体   繁体   中英

'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?

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",]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM