I am attempting to use lapply for simple descriptive statistics on a list of lists. here is an example of my code for the list:
varlist <- list(
datafile$Ho,
datafile$Hd,
datafile$Vo,
datafile$Vd,
datafile$TDC,
datafile$W,
datafile$Ao,
datafile$Ad,
datafile$Freq)
I create a dataframe to store the new values called descript:
descript <- data.frame(
mean = as.numeric(),
sd = as.numeric(),
range = as.numeric(),
median = as.numeric())
All of that works fine, however as soon as I throw it into lapply I get an issue stating the replacement has 2 rows, data has 1
lapply(varlist,function(x){
descript$mean <- mean(x,na.rm = TRUE)
descript$sd <- sd(x,na.rm = TRUE)
descript$range <- range(x,na.rm = TRUE)
descript$median <- median(x,na.rm = TRUE)
})
I have looked at other coding questions of the same kind however each answer seems to be application specific. I'm not the greatest at coding admittedly, but if someone could explain what the issue is or how it is generated and give me a solution to my problem I would greatly appreciate it, thanks