将数据帧列表中的数据帧绑定到不同数据帧列表中的数据帧
Rbind a dataframe from a list of dataframes to a dataframe in a different list of dataframes
我有两个数据框列表,两个列表中的每个数据框都具有相同的名称和相同的列数。我想将列表 2 中匹配的数据帧名称绑定到列表 1 中。
我下面两个列表的片段
l1 <-list(Fe = structure(c("Min", "Max", "Median", "Mean", "Std Dev",
"Coeff. Variation", "Dev. From Cert Mean", " NA", " NA",
" NA", " NaN", " NA", " NA", " NaN", "56.18", "56.83",
"56.50", "56.48", "0.218", "0.39", " 0.13", "56.31", "56.53",
"56.41", "56.41", "0.080", "0.14", " 0.01", "56.29", "56.39",
"56.32", "56.33", "0.034", "0.06", "-0.15", "56.40", "56.73",
"56.51", "56.53", "0.125", "0.22", " 0.22", "56.26", "56.53",
"56.32", "56.36", "0.116", "0.20", "-0.09", "56.20", "56.70",
"56.50", "56.45", "0.176", "0.31", " 0.08", "56.10", "56.46",
"56.36", "56.29", "0.150", "0.27", "-0.21", "56.10", "56.83",
"56.41", "56.41", "0.153", "0.27", ""), .Dim = c(7L, 10L), .Dimnames = list(
c("LabMinSummary", "LabMaxSummary", "LabMedianSummary", "LabMeanSummary",
"lab.SDSummary", "cv.summmary", "LabDevMean.Summary"), c("",
"2", "3", "4", "5", "7", "8", "10", "12", ""))), SiO2 = structure(c("Min",
"Max", "Median", "Mean", "Std Dev", "Coeff. Variation", "Dev. From Cert Mean",
"7.63", "7.73", "7.67", "7.67", "0.033", "0.44", "-1.09", "7.59",
"7.84", "7.72", "7.71", "0.091", "1.18", "-0.55", "7.62", "7.81",
"7.70", "7.72", "0.079", "1.02", "-0.48", "7.84", "7.96", "7.89",
"7.89", "0.048", "0.61", " 1.75", "7.65", "7.83", "7.76", "7.76",
"0.060", "0.77", " 0.01", "7.68", "7.94", "7.83", "7.82", "0.086",
"1.10", " 0.84", "7.62", "7.87", "7.79", "7.77", "0.111", "1.43",
" 0.19", "7.64", "7.82", "7.70", "7.70", "0.065", "0.84", "-0.68",
"7.59", "7.96", "7.74", "7.74", "0.097", "1.25", ""), .Dim = c(7L,
10L), .Dimnames = list(c("LabMinSummary", "LabMaxSummary", "LabMedianSummary",
"LabMeanSummary", "lab.SDSummary", "cv.summmary", "LabDevMean.Summary"
), c("", "2", "3", "4", "5", "7", "8", "10", "12", ""))), Al2O3 = structure(c("Min",
"Max", "Median", "Mean", "Std Dev", "Coeff. Variation", "Dev. From Cert Mean",
"2.00", "2.03", "2.01", "2.01", "0.010", "0.52", "-0.16", "2.00",
"2.03", "2.01", "2.01", "0.010", "0.52", "-0.16", "1.99", "2.03",
"2.01", "2.01", "0.013", "0.66", "-0.49", "2.02", "2.05", "2.02",
"2.03", "0.012", "0.58", " 0.50", " NA", " NA", " NA", " NaN",
" NA", " NA", " NaN", "2.01", "2.05", "2.04", "2.03", "0.017",
"0.82", " 0.78", "1.98", "2.02", "2.01", "2.01", "0.015", "0.77",
"-0.45", " NA", " NA", " NA", " NaN", " NA", " NA", " NaN",
"1.98", "2.05", "2.01", "2.01", "0.016", "0.77", ""), .Dim = c(7L,
10L), .Dimnames = list(c("LabMinSummary", "LabMaxSummary", "LabMedianSummary",
"LabMeanSummary", "lab.SDSummary", "cv.summmary", "LabDevMean.Summary"
), c("", "2", "3", "4", "5", "7", "8", "10", "12", ""))))
l2 <- list(Fe = c("Count", "0", "6", "6", "6", "6", "6", "6", "6",
"42"), SiO2 = c("Count", "6", "6", "6", "6", "6", "6", "6", "6",
"48"), Al2O3 = c("Count", "6", "6", "6", "6", "0", "6", "6",
"0", "36"))
我试过了
l3 <- Map(rbind(l1,l2))
l3 <- do.call(rbind,Map(l1,l2))
不太确定从这里去哪里
``
您可以像下面那样尝试rbind
> Map(rbind, l1, l2)
$Fe
2 3 4 5
LabMinSummary "Min" " NA" "56.18" "56.31" "56.29"
LabMaxSummary "Max" " NA" "56.83" "56.53" "56.39"
LabMedianSummary "Median" " NA" "56.50" "56.41" "56.32"
LabMeanSummary "Mean" " NaN" "56.48" "56.41" "56.33"
lab.SDSummary "Std Dev" " NA" "0.218" "0.080" "0.034"
cv.summmary "Coeff. Variation" " NA" "0.39" "0.14" "0.06"
LabDevMean.Summary "Dev. From Cert Mean" " NaN" " 0.13" " 0.01" "-0.15"
"Count" "0" "6" "6" "6"
7 8 10 12
LabMinSummary "56.40" "56.26" "56.20" "56.10" "56.10"
LabMaxSummary "56.73" "56.53" "56.70" "56.46" "56.83"
LabMedianSummary "56.51" "56.32" "56.50" "56.36" "56.41"
LabMeanSummary "56.53" "56.36" "56.45" "56.29" "56.41"
lab.SDSummary "0.125" "0.116" "0.176" "0.150" "0.153"
cv.summmary "0.22" "0.20" "0.31" "0.27" "0.27"
LabDevMean.Summary " 0.22" "-0.09" " 0.08" "-0.21" ""
"6" "6" "6" "6" "42"
$SiO2
2 3 4 5
LabMinSummary "Min" "7.63" "7.59" "7.62" "7.84"
LabMaxSummary "Max" "7.73" "7.84" "7.81" "7.96"
LabMedianSummary "Median" "7.67" "7.72" "7.70" "7.89"
LabMeanSummary "Mean" "7.67" "7.71" "7.72" "7.89"
lab.SDSummary "Std Dev" "0.033" "0.091" "0.079" "0.048"
cv.summmary "Coeff. Variation" "0.44" "1.18" "1.02" "0.61"
LabDevMean.Summary "Dev. From Cert Mean" "-1.09" "-0.55" "-0.48" " 1.75"
"Count" "6" "6" "6" "6"
7 8 10 12
LabMinSummary "7.65" "7.68" "7.62" "7.64" "7.59"
LabMaxSummary "7.83" "7.94" "7.87" "7.82" "7.96"
LabMedianSummary "7.76" "7.83" "7.79" "7.70" "7.74"
LabMeanSummary "7.76" "7.82" "7.77" "7.70" "7.74"
lab.SDSummary "0.060" "0.086" "0.111" "0.065" "0.097"
cv.summmary "0.77" "1.10" "1.43" "0.84" "1.25"
LabDevMean.Summary " 0.01" " 0.84" " 0.19" "-0.68" ""
"6" "6" "6" "6" "48"
$Al2O3
2 3 4 5
LabMinSummary "Min" "2.00" "2.00" "1.99" "2.02"
LabMaxSummary "Max" "2.03" "2.03" "2.03" "2.05"
LabMedianSummary "Median" "2.01" "2.01" "2.01" "2.02"
LabMeanSummary "Mean" "2.01" "2.01" "2.01" "2.03"
lab.SDSummary "Std Dev" "0.010" "0.010" "0.013" "0.012"
cv.summmary "Coeff. Variation" "0.52" "0.52" "0.66" "0.58"
LabDevMean.Summary "Dev. From Cert Mean" "-0.16" "-0.16" "-0.49" " 0.50"
"Count" "6" "6" "6" "6"
7 8 10 12
LabMinSummary " NA" "2.01" "1.98" " NA" "1.98"
LabMaxSummary " NA" "2.05" "2.02" " NA" "2.05"
LabMedianSummary " NA" "2.04" "2.01" " NA" "2.01"
LabMeanSummary " NaN" "2.03" "2.01" " NaN" "2.01"
lab.SDSummary " NA" "0.017" "0.015" " NA" "0.016"
cv.summmary " NA" "0.82" "0.77" " NA" "0.77"
LabDevMean.Summary " NaN" " 0.78" "-0.45" " NaN" ""
"0" "6" "6" "0" "36"
或使用map2
library(purrr)
map2(l1, l2, rbind)
我有两个数据框列表,两个列表中的每个数据框都具有相同的名称和相同的列数。我想将列表 2 中匹配的数据帧名称绑定到列表 1 中。
我下面两个列表的片段
l1 <-list(Fe = structure(c("Min", "Max", "Median", "Mean", "Std Dev",
"Coeff. Variation", "Dev. From Cert Mean", " NA", " NA",
" NA", " NaN", " NA", " NA", " NaN", "56.18", "56.83",
"56.50", "56.48", "0.218", "0.39", " 0.13", "56.31", "56.53",
"56.41", "56.41", "0.080", "0.14", " 0.01", "56.29", "56.39",
"56.32", "56.33", "0.034", "0.06", "-0.15", "56.40", "56.73",
"56.51", "56.53", "0.125", "0.22", " 0.22", "56.26", "56.53",
"56.32", "56.36", "0.116", "0.20", "-0.09", "56.20", "56.70",
"56.50", "56.45", "0.176", "0.31", " 0.08", "56.10", "56.46",
"56.36", "56.29", "0.150", "0.27", "-0.21", "56.10", "56.83",
"56.41", "56.41", "0.153", "0.27", ""), .Dim = c(7L, 10L), .Dimnames = list(
c("LabMinSummary", "LabMaxSummary", "LabMedianSummary", "LabMeanSummary",
"lab.SDSummary", "cv.summmary", "LabDevMean.Summary"), c("",
"2", "3", "4", "5", "7", "8", "10", "12", ""))), SiO2 = structure(c("Min",
"Max", "Median", "Mean", "Std Dev", "Coeff. Variation", "Dev. From Cert Mean",
"7.63", "7.73", "7.67", "7.67", "0.033", "0.44", "-1.09", "7.59",
"7.84", "7.72", "7.71", "0.091", "1.18", "-0.55", "7.62", "7.81",
"7.70", "7.72", "0.079", "1.02", "-0.48", "7.84", "7.96", "7.89",
"7.89", "0.048", "0.61", " 1.75", "7.65", "7.83", "7.76", "7.76",
"0.060", "0.77", " 0.01", "7.68", "7.94", "7.83", "7.82", "0.086",
"1.10", " 0.84", "7.62", "7.87", "7.79", "7.77", "0.111", "1.43",
" 0.19", "7.64", "7.82", "7.70", "7.70", "0.065", "0.84", "-0.68",
"7.59", "7.96", "7.74", "7.74", "0.097", "1.25", ""), .Dim = c(7L,
10L), .Dimnames = list(c("LabMinSummary", "LabMaxSummary", "LabMedianSummary",
"LabMeanSummary", "lab.SDSummary", "cv.summmary", "LabDevMean.Summary"
), c("", "2", "3", "4", "5", "7", "8", "10", "12", ""))), Al2O3 = structure(c("Min",
"Max", "Median", "Mean", "Std Dev", "Coeff. Variation", "Dev. From Cert Mean",
"2.00", "2.03", "2.01", "2.01", "0.010", "0.52", "-0.16", "2.00",
"2.03", "2.01", "2.01", "0.010", "0.52", "-0.16", "1.99", "2.03",
"2.01", "2.01", "0.013", "0.66", "-0.49", "2.02", "2.05", "2.02",
"2.03", "0.012", "0.58", " 0.50", " NA", " NA", " NA", " NaN",
" NA", " NA", " NaN", "2.01", "2.05", "2.04", "2.03", "0.017",
"0.82", " 0.78", "1.98", "2.02", "2.01", "2.01", "0.015", "0.77",
"-0.45", " NA", " NA", " NA", " NaN", " NA", " NA", " NaN",
"1.98", "2.05", "2.01", "2.01", "0.016", "0.77", ""), .Dim = c(7L,
10L), .Dimnames = list(c("LabMinSummary", "LabMaxSummary", "LabMedianSummary",
"LabMeanSummary", "lab.SDSummary", "cv.summmary", "LabDevMean.Summary"
), c("", "2", "3", "4", "5", "7", "8", "10", "12", ""))))
l2 <- list(Fe = c("Count", "0", "6", "6", "6", "6", "6", "6", "6",
"42"), SiO2 = c("Count", "6", "6", "6", "6", "6", "6", "6", "6",
"48"), Al2O3 = c("Count", "6", "6", "6", "6", "0", "6", "6",
"0", "36"))
我试过了
l3 <- Map(rbind(l1,l2))
l3 <- do.call(rbind,Map(l1,l2))
不太确定从这里去哪里
``
您可以像下面那样尝试rbind
> Map(rbind, l1, l2)
$Fe
2 3 4 5
LabMinSummary "Min" " NA" "56.18" "56.31" "56.29"
LabMaxSummary "Max" " NA" "56.83" "56.53" "56.39"
LabMedianSummary "Median" " NA" "56.50" "56.41" "56.32"
LabMeanSummary "Mean" " NaN" "56.48" "56.41" "56.33"
lab.SDSummary "Std Dev" " NA" "0.218" "0.080" "0.034"
cv.summmary "Coeff. Variation" " NA" "0.39" "0.14" "0.06"
LabDevMean.Summary "Dev. From Cert Mean" " NaN" " 0.13" " 0.01" "-0.15"
"Count" "0" "6" "6" "6"
7 8 10 12
LabMinSummary "56.40" "56.26" "56.20" "56.10" "56.10"
LabMaxSummary "56.73" "56.53" "56.70" "56.46" "56.83"
LabMedianSummary "56.51" "56.32" "56.50" "56.36" "56.41"
LabMeanSummary "56.53" "56.36" "56.45" "56.29" "56.41"
lab.SDSummary "0.125" "0.116" "0.176" "0.150" "0.153"
cv.summmary "0.22" "0.20" "0.31" "0.27" "0.27"
LabDevMean.Summary " 0.22" "-0.09" " 0.08" "-0.21" ""
"6" "6" "6" "6" "42"
$SiO2
2 3 4 5
LabMinSummary "Min" "7.63" "7.59" "7.62" "7.84"
LabMaxSummary "Max" "7.73" "7.84" "7.81" "7.96"
LabMedianSummary "Median" "7.67" "7.72" "7.70" "7.89"
LabMeanSummary "Mean" "7.67" "7.71" "7.72" "7.89"
lab.SDSummary "Std Dev" "0.033" "0.091" "0.079" "0.048"
cv.summmary "Coeff. Variation" "0.44" "1.18" "1.02" "0.61"
LabDevMean.Summary "Dev. From Cert Mean" "-1.09" "-0.55" "-0.48" " 1.75"
"Count" "6" "6" "6" "6"
7 8 10 12
LabMinSummary "7.65" "7.68" "7.62" "7.64" "7.59"
LabMaxSummary "7.83" "7.94" "7.87" "7.82" "7.96"
LabMedianSummary "7.76" "7.83" "7.79" "7.70" "7.74"
LabMeanSummary "7.76" "7.82" "7.77" "7.70" "7.74"
lab.SDSummary "0.060" "0.086" "0.111" "0.065" "0.097"
cv.summmary "0.77" "1.10" "1.43" "0.84" "1.25"
LabDevMean.Summary " 0.01" " 0.84" " 0.19" "-0.68" ""
"6" "6" "6" "6" "48"
$Al2O3
2 3 4 5
LabMinSummary "Min" "2.00" "2.00" "1.99" "2.02"
LabMaxSummary "Max" "2.03" "2.03" "2.03" "2.05"
LabMedianSummary "Median" "2.01" "2.01" "2.01" "2.02"
LabMeanSummary "Mean" "2.01" "2.01" "2.01" "2.03"
lab.SDSummary "Std Dev" "0.010" "0.010" "0.013" "0.012"
cv.summmary "Coeff. Variation" "0.52" "0.52" "0.66" "0.58"
LabDevMean.Summary "Dev. From Cert Mean" "-0.16" "-0.16" "-0.49" " 0.50"
"Count" "6" "6" "6" "6"
7 8 10 12
LabMinSummary " NA" "2.01" "1.98" " NA" "1.98"
LabMaxSummary " NA" "2.05" "2.02" " NA" "2.05"
LabMedianSummary " NA" "2.04" "2.01" " NA" "2.01"
LabMeanSummary " NaN" "2.03" "2.01" " NaN" "2.01"
lab.SDSummary " NA" "0.017" "0.015" " NA" "0.016"
cv.summmary " NA" "0.82" "0.77" " NA" "0.77"
LabDevMean.Summary " NaN" " 0.78" "-0.45" " NaN" ""
"0" "6" "6" "0" "36"
或使用map2
library(purrr)
map2(l1, l2, rbind)