I used read.csv to import a CSV file with numeric values where the CSV seperator is ";", the decimal seperator is "," and additional the thousend seperator is "."Hist <- read.csv(file = "XXXX", header = T, sep = ";", dec =",", stringsAsFactors=FALSE)我将其转换为data.table ...I transformed it in a data.table ...Hist <- data.table(Hist)它看起来像这样: Date Value# 2017-11-12 12.456,89# 2017-11-10 13.234,99# 2017-11-08 14.123,45现在,我想将值"列的类/格式更改为数字,因为我想使用它进行计算.但是我尝试的所有方法都没有效果.例如:Now I want to change the class/format of the column "Value" to numeric since I want to calculate with it. But everything I tried did not worked. For example:Hist[, Value := as.numeric(Value)]正在创建错误:警告信息:在eval(jsub,SDenv,parent.frame())中:强制引入的NAs Warning message: In eval(jsub, SDenv, parent.frame()) : NAs introduced by coercion有人可以帮忙吗?推荐答案它们被视为字符串.为了将它们转换为数字,请删除千位分隔符(.),然后将小数点分隔符(,)转换为点.They are read as strings. In order to convert them to a number remove the thousands separator (.) and then convert the decimal separator (,) to a point.Hist$Value = as.numeric(gsub(",",".",(gsub("\\.","",Hist$Value))))与以下相同:noPoints = gsub("\\.", "", Hist$Value)commaToPoint = gsub(",", ".", noPoints)Hist$Value = as.numeric(commaToPoint) 这篇关于使用千位分隔符将字符更改为data.frame(as.numeric)中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-05 21:16