I have csv file with ID and variable. It looks like this
我有带ID和变量的csv文件。看起来像这样
ID V1
1 0
2 -0,12
3 0,05
....
if I use hist(mydata$V1) I get an error message
如果我使用hist(mydata $ V1),我会收到一条错误消息
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!
但是使用变量ID(mydata $ ID)它可以工作。变量V1,0在第一个位置有什么不好?谢谢!
2 个解决方案
#1
1
What is bad with variable V1, 0 at first place?
变量V1,0在第一个位置有什么不好?
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.
它必须是数字。看起来你在那里有一些逗号,R正在考虑它是一个因子或字符类型列。
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.
如果您的目标是将列读入数字,将逗号解释为小数分隔符,请查看此问题。
#2
0
Dont know why, but when I manualy imported data from dataset and changed encoding from automatic to UTF it works.
不知道为什么,但是当我从数据集中手动导入数据并将编码从自动更改为UTF时,它可以工作。
#1
1
What is bad with variable V1, 0 at first place?
变量V1,0在第一个位置有什么不好?
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.
它必须是数字。看起来你在那里有一些逗号,R正在考虑它是一个因子或字符类型列。
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.
如果您的目标是将列读入数字,将逗号解释为小数分隔符,请查看此问题。
#2
0
Dont know why, but when I manualy imported data from dataset and changed encoding from automatic to UTF it works.
不知道为什么,但是当我从数据集中手动导入数据并将编码从自动更改为UTF时,它可以工作。