I think you need to use apply
to tell R to use sd()
on the wanted columns of each list element.
Please see the example below, iris
is a baseR dataset you should be able to make it run.
df <- split(iris, iris$Species) # create a toy dataset
lapply(df, function(x) colMeans(x[1:3])) # what you have done so far
# you can achieve the same thing using
lapply(df, function(x) apply(x[1:3], 2, mean))
lapply(df, function(x) apply(x[1:3], 2, sd)) # this might be what you want
The output:
> lapply(df, function(x) apply(x[1:3], 2, sd))
$setosa
Sepal.Length Sepal.Width Petal.Length
0.3524897 0.3790644 0.1736640
$versicolor
Sepal.Length Sepal.Width Petal.Length
0.5161711 0.3137983 0.4699110
$virginica
Sepal.Length Sepal.Width Petal.Length
0.6358796 0.3224966 0.5518947