r - Performance of a loop for modifiying a factor -
so have following loop:
for(i in 1:dim(d)[1]) { if(d$countryname[i] %in% c("italy","spain","canada","brazil","united states","france","mexico","colombia","peru","chile","argentina","ecuador")) {next} else {d$countryname[i] <- "others"} }
the "d" dataframe has more 6,5 million rows , d$countryname factor.
is there way make faster? very slow. thank you.
how about:
log <- d$countryname %in% c("italy","spain","canada","brazil","united states","france","mexico","colombia","peru","chile","argentina","ecuador") d$countryname[!log] <- "others"
Comments
Post a Comment