Reputation: 814
I have a set of data frames each with different column names, e.g. frameOne
looks like
Q2 Q6 Q9
1 1 0 0
2 0 1 1
...
N 1 1 0
and frameTwo
is
Q1 Q5 Q9 Q22
1 1 1 0 1
2 1 0 1 0
...
N 1 1 1 0
How would I calculate the mean and standard deviation of the entire frame without explicitly stating the column names?
Upvotes: 1
Views: 6930
Reputation: 70603
Based on your answer, I'm guessing you're after this.
df1 <- as.data.frame(matrix(runif(9), ncol = 3))
df2 <- as.data.frame(matrix(runif(9), ncol = 3))
df3 <- as.data.frame(matrix(runif(9), ncol = 3))
df4 <- as.data.frame(matrix(runif(9), ncol = 3))
my.objs <- ls(pattern = "df")
sapply(my.objs, FUN = function(x) {
st <- as.vector(as.matrix(get(x)))
data.frame(mean = mean(st), sd = sd(st))
})
df1 df2 df3 df4
mean 0.4967452 0.4426861 0.5198141 0.3460732
sd 0.2533854 0.2179547 0.3106693 0.3179838
Upvotes: 3