I have a list (df) of data frames of differing lengths, indexed by years such that a proxy of the data looks like:
df
$df1
X..i..
1999 10
1998 13
1997 14
$df2
X..i..
1999 20
1998 11
$df3
X..i..
1999 17
1998 8
1997 9
1996 19
I would like to combine these data frames to a single data frame using and preserving the index/rownames
So that:
df_all
Index df1 df2 df3
1999 10 20 17
1998 13 11 8
1997 14 n/a 9
1996 n/a n/a 19
Edit:
smalldflist <- lapply(bai_df, function(i) head(i, 10))
dput(smalldflist)
Produces the following output:
structure(list(IN_DonaldsonWoods_QUAL.txt = structure(list(X..i.. = c(4.5528243479162, 32.6474339976978, 52.7116018957456, 170.932582874866, 227.0430440174, 191.462399206825, 226.94053541991, 274.854835798233, 336.457600434571, 409.132933511232)), .Names = "X..i..", row.names = c("1725", "1726", "1727", "1728", "1729", "1730", "1731", "1732", "1733", "1734"), class = "data.frame"), IN_DonaldsonWoods_QURU.txt = structure(list( X..i.. = c(4.33729067152776, 5.72878688080428, 13.0247658962315, 22.0205798005054, 25.9885943197615, 18.9273551074104, 43.5197887382031, 58.2775710248884, 72.9225976242458, 73.0466756114972)), .Names = "X..i..", row.names = c("1827", "1828", "1829", "1830", "1831", "1832", "1833", "1834", "1835", "1836"), class = "data.frame"), IN_DonaldsonWoods_QUVE.txt = structure(list( X..i.. = c(7.87253273859391, 18.9481296742303, 42.5055176960097, 62.9980951594496, 88.906442207264, 74.2523230533691, 106.911242713809, 152.445167763284, 192.399603839633, 221.263660216113)), .Names = "X..i..", row.names = c("1731", "1732", "1733", "1734", "1735", "1736", "1737", "1738", "1739", "1740"), class = "data.frame"), IN_LillyDickey_QUAL.txt = structure(list( X..i.. = c(8.29576810088555, 17.2934968058816, 31.2091720401804, 33.8966066349882, 47.6496887415004, 32.9921546763907, 82.2281435044324, 108.068226885475, 103.894002151431, 110.255812097949)), .Names = "X..i..", row.names = c("1863", "1864", "1865", "1866", "1867", "1868", "1869", "1870", "1871", "1872"), class = "data.frame"), IN_LillyDickey_QUMO.txt = structure(list( X..i.. = c(3.42413493048312, 8.0847630303073, 19.6833503197648, 13.791136218324, 21.4638165402601, 30.6707376168741, 30.8789937938806, 26.8661212585221, 24.0732956549621, 29.7872997715364)), .Names = "X..i..", row.names = c("1867", "1868", "1869", "1870", "1871", "1872", "1873", "1874", "1875", "1876"), class = "data.frame"), IN_Pioneers_QUAL.txt = structure(list( X..i.. = c(9.14340435634345, 23.5108626053757, 33.8507393822465, 46.1027716604662, 57.5247983011993, 50.5892015892391, 92.2448163706925, 225.832932372368, 278.367628044195, 193.931508820174)), .Names = "X..i..", row.names = c("1817", "1818", "1819", "1820", "1821", "1822", "1823", "1824", "1825", "1826"), class = "data.frame"), IN_Pioneers_QURU.txt = structure(list( X..i.. = c(122.443727611702, 658.649900930018, 830.471777578934, 843.357139228152, 1725.6495913006, 1244.38668477703, 973.00892131628, 1294.7441782001, 1717.18570086886, 1676.63841798444)), .Names = "X..i..", row.names = c("1861", "1862", "1863", "1864", "1865", "1866", "1867", "1868", "1869", "1870"), class = "data.frame"), OH_JohnsonWoods_QUAL.txt = structure(list( X..i.. = c(1.9113449704439, 3.39794661412248, 5.32688450342693, 6.41921626908008, 11.0307601252838, 13.0825342873437, 15.843680070585, 16.885746353779, 20.1011664347289, 19.853294774361)), .Names = "X..i..", row.names = c("1626", "1627", "1628", "1629", "1630", "1631", "1632", "1633", "1634", "1635"), class = "data.frame")), .Names = c("IN_DonaldsonWoods_QUAL.txt", "IN_DonaldsonWoods_QURU.txt", "IN_DonaldsonWoods_QUVE.txt", "IN_LillyDickey_QUAL.txt", "IN_LillyDickey_QUMO.txt", "IN_Pioneers_QUAL.txt", "IN_Pioneers_QURU.txt", "OH_JohnsonWoods_QUAL.txt"))
dput(df)
? This will make it easier to work with your data and work on a solution. - beigelsmalldfList <- lapply(dfList, function(i) head(i, 10)[c("col1", "col2", "col3")])
. Thendput(smalldfList)
, then post that gobblyegook here (trust us we know how to use it). - Parfait