Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- own_imp <- function(dt){
- for (column in 1:ncol(dt)){
- corr <- sapply(c(names(dt[,-column])),
- function(x) cor(dt[,column], dt[,x], use = "p"))
- corr_dec <- sort(corr, decreasing = TRUE)
- imp.use <- names(corr_dec[1])
- lm.cf <- lm(reformulate(imp.use, colnames(dt[column])), dt)$coef
- dt[, column] <- ifelse(is.na(dt[, column]), lm.cf[1] + dt[[imp.use]] *lm.cf[2], dt[,column])
- }
- return(dt)
- }
- file = "https://www.dropbox.com/s/jw8oqc9816ul8jq/GRP_outside_d20.csv?dl=1"
- GRP_data = read.csv(file = file)
- new_data <- own_imp(GRP_data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement