I'm trying to get the densities of numeric columns in a data frame and to assign them to new variables.
I'm using this function, but when I use it, it happens nothing. I'm kind of lost... Could you help me?
densities <- function(data.input, dense){
for(i in 1:ncol(data.input)){
if(is.numeric(data.input[,i]) == TRUE){
dense <- density(data.input[, i])
names(dense) <- paste(c("density"), colnames(data.input)[i], names(data.input), sep = ".")
return(dense) ## I don't know how to make it return the created variable and have it in the environment
}else{
next
}
}
}
Sorry if the answer is too obvious