I have a list of data.frames.
A <- list(aa = data.frame(var1 = c(1:3), varb = c(1:3), abu = c(1:3)),
bb = data.frame(abu = c(1:3), var1 = c(1:3), vara = c(1:3), varb = c(1:3)),
cc = data.frame(varb = c(1:3), g = c(1:3)))
output
> A
$aa
var1 varb abu
1 1 1 1
2 2 2 2
3 3 3 3
$bb
abu var1 vara varb
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
$cc
varb g
1 1 1
2 2 2
3 3 3
>
How can I order variables in these data.frames so that the order of the variables is the same as the data.frame $aa has? If the data.frame does not have a correspondign variable, the variable should be created into this data.frame containing NA data. Any idea how to achieve this?
do you want something like this?
How do you want to do with the variables that do not appear in
A$aa, for example,A$bb$vara?Slightly updated for preserving other variables