I'm trying to add thousands separator into certain column values. In this case column x2 and x1, but I failed to so so. Here is my code :
my_data <- data.frame(x1 = c("a","b", "c"),
x2 = c(10000, 5000, 5000),
x3 = 1001:1003)
col_conv <- c("x3","x2")
my_data_updated <- my_data
my_data_updated[ , col_conv] <- lapply(my_data_updated[ , col_conv],
function(x){ as.numeric(gsub(",", "", x)) })
the data frame format is not changing
thank you