I want to round off specific columns with each column have different rounding values. I tried with the following code but it gives an error:
roundCols <-function(repo, namcol, digiround){
repo[,"namcol"] = round(repo[,"namcol"], digits = digiround)
round.staus = TRUE
return(round.staus)
}
round.staus = FALSE
ils <- config[13]$ignoreColumns
ils <- gsub("\\{|\\}", "", ils)
ils <- ils %>% str_replace_all("\\&", ",")
coldrp <- unlist(strsplit(ils, "\\,"))
coldrp = gsub("[^a-zA-Z]+", ".", coldrp)
td <- fread(config[13]$save.location,stringsAsFactors = FALSE,drop=coldrp,blank.lines.skip = TRUE)
col_rnm <- c(names(td[,2]),names(td[,3])) #it has 2 column who's will be round off
col_rd <- c(2,3) #it gives digits how much rounding off required
for (i in 1:length(col_rnm)) {
round.staus = roundCols(td,col_rnm,col_rd[i])
}
td
error is :
Error in
[.data.table
(repo, , "namcol") : column(s) not found: namcol
I tried the same given in function on a console which gives an exact result.
Expected Output:
Account Chargeable.Capacity Expected.Capacity.in.30.days Deviation
Kishore 0.01 0.007 3.778268e-11
Initially My data :
Account Chargeable.Capacity Expected.Capacity.in.30.days Deviation
Kishore 0.007124108 0.007283185 3.778268e-11
above what is expected from the function given the code. Help me to solve that error. The effort will be appreciated.