I created a function that took in a data frame and returned the mean and median for numeric variables in that data frame. When I test the function, there are 3 null values. How would I remove null values from this?
df.numeric.summary <- function(data.frame1){
variable.list=list()
numcols <- sapply(data,is.numeric)
for(i in 1:ncol(data.frame1)){
if (is.numeric(data.frame1[[i]]) == TRUE) {
variable.list[[i]]=list(c("Mean"=mean(data.frame1[[i]], na.rm = TRUE),"Median"=median(data.frame1[[i]]), "IQR"=IQR(data.frame1[[i]])))
}
}
return(variable.list)
}
My output looks like this:
[[1]]
NULL
[[2]]
NULL
[[3]]
NULL
[[4]]
[[4]][[1]]
Mean Median IQR
10.76687 3.56400 7.75100
[[5]]
[[5]][[1]]
Mean Median IQR
10.43467 1.40000 4.50100
[[6]]
[[6]][[1]]
Mean Median IQR
3.701434 0.839000 2.429500
whereas the output should look like this
$Pb1
Mean Median IQR
10.76687 3.56400 7.75100
$Pb2
Mean Median IQR
10.43467 1.40000 4.50100
$Pb3
Mean Median IQR
3.701434 0.839000 2.429500