trying to create a table to calculate the mean of my data, but sapply won't work, it keeps giving me the error that 'x' must be an array of at least two dimensions
here's my code
#Question 1
set.seed(10000)
v <- c(0.1,0.5,1,2,5,10,100)
lyst <- list()
for(i in v)
{
for(j in v)
{
elementname <- paste0(as.character(i),"-",as.character(j))
print(elementname)
lyst[[elementname]] <- rgamma(10000,i,j)
}
}
#Question 2
pdf("Histogr4m.pdf",width = 20, height = 10)
par(mfcol=c(7,7))
for(x in names(lyst))
{
hist(lyst[[x]],
xlab = "Value",
main = paste("Alpha-Lambda:",x))
}
dev.off()
#Question 3
sampleMean <- sapply(lyst, colMeans)
I think the problem is caused by the fact that lyst
is a class list object. Thus, it might be a better approach to use lapply
to apply a function to every element of this list. You can do that by using the following code:
sampleMean <- lapply(lyst, mean)