我想在r中的情节中显示大数字。但是我得到了这个错误:
我的号码是:
[1] "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11" "9,02E+11"
[8] "9,02E+11" "9,02E+11" "9,02E+11" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12"
[15] "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "8,45E+12" "1,31E+13"
[22] "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13" "1,31E+13"
[29] "1,31E+13" "1,31E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13"
[36] "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,48E+13" "1,36E+13" "1,36E+13"
[43] "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13" "1,36E+13"
[50] "1,36E+13" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12"
[57] "9,59E+12" "9,59E+12" "9,59E+12" "9,59E+12" "2,64E+12" "2,64E+12" "2,64E+12"
[64] "2,64E+12"
和简单的代码:
plot(dataliste,type="l")
我正在阅读一份文件中的svalues,我不能指定ylim的限制,因为它们的范围很广。我该怎么做才能解决这个问题
答案 0 :(得分:5)
试试这个:
plot(sapply(dataliste, function(x)gsub(",", ".", x)))
正如RomanLuštrik指出的那样,你很可能在你的数据中有字符。您通常可以绘制它们或使用as.numeric转换它们。但是,由于您的字符串中有,
而不是.
,因此转换为数字会失败。
例如:
> as.numeric("9,02E+11")
[1] NA
Warning message:
NAs introduced by coercion
> as.numeric("9.02E+11")
[1] 9.02e+11
使用gsub,如上所述,您可以用,
替换每个数字的.
,并且绘图应该有用。