I have a small problem. I know using data.frame
and loop is not that good and my function doesn't update the columns I want to change. Any idea on how to make this function work? Thanks in advance
Func = function(data,k){
result_freq = data.frame(apply(data,2,function(x) length(unique(x))))
for (w in 1:nrow(result_freq)){
if (result_freq[w,]>(nrow(data)/3)) {
data[,w] = as.integer(paste(round( data[,w]/ 1e3)))
}
}
return(data)
}
Func(data,5)
My original data is something like that, and i want this column to be cut by 1K and updated in the original data.frame
1300 => 1
1421 => 1
34535 => 34