简体   繁体   中英

Histogram in R. Problem with Function hist()

I have csv file with ID and variable. It looks like this

    ID   V1
    1    0
    2   -0,12
    3    0,05
    ....

if I use hist(mydata$V1) I get an error message

Error in hist.default(mydata$V1) : 'x' must be numeric

But with variable ID (mydata$ID) it works. What is bad with variable V1, 0 at first place? Thanks!

What is bad with variable V1, 0 at first place?

It must be numeric. Looks like you've got some commas in there and R is considering it to be a factor or character type column.

Try

hist(table(mydata$V1))

or

barplot(table(mydata$V1))

to get a histogram of the resulting factor.

Check out this question if your goal is to read in the column as numeric, interpreting the comma as a decimal separator.

不知道为什么,但是当我手动从数据集中导入数据并将编码从自动更改为UTF时,它可以工作。

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