列表和data.frame组合(每行的行数相同但长度不同)

时间:2018-02-16 02:00:07

标签: r list dataframe dplyr data.table

如何在R中组合不同的列表和data.frame(同一行,但每列的长度不同)?

我有两个LIST和一个data.frame,COL01,COL02和COL03,我想把它们组合成一个data.frame

dat<- (aq_measurements(country = “country”, city = “city”, location = “location”, parameter = “pollutant choice”, date_from = “YYYdateY-MM-DD”, date_to = “YYYY-MM-DD”)

我期望的结果是一个包含2个列表列和一个数据帧的数据框

COL01 =
structure(list(V1 = c(-0.0431597784900261, -0.518148142834806, 
-0.237032580263406, -0.920434206514568, -0.95436194682491, -0.556922703189482
), V2 = c(-0.518148142834806, -0.237032580263406, -0.920434206514568, 
-0.95436194682491, -0.556922703189482), V3 = c(-0.237032580263406, 
-0.920434206514568, -0.95436194682491, -0.556922703189482, -0.988289687135251
), V4 = c(-0.920434206514568, -0.95436194682491, -0.556922703189482, 
-0.988289687135251, 0.0569519413796151), V5 = c(-0.95436194682491, 
-0.556922703189482, -0.988289687135251, 0.0569519413796151, 0.0981633964482812
), V6 = c(-0.95436194682491, -0.556922703189482, -0.988289687135251, 
0.0569519413796151, 0.0981633964482812, -1.60696055701778)), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6"))

COL02 = 
structure(list(V1 = c(0.490280732997843, -0.232516232554677, 
0.237972180098397, -0.988223009354951, -1.33316658650733, -0.603056329566425
), V2 = c(-0.232516232554677, 0.237972180098397, -0.988223009354951, 
-1.33316658650733, -0.603056329566425), V3 = c(0.237972180098397, 
-0.988223009354951, -1.33316658650733, -0.603056329566425, -0.999192946437536
), V4 = c(-0.988223009354951, -1.33316658650733, -0.603056329566425, 
-0.999192946437536, 0.00282420705837356), V5 = c(-1.33316658650733, 
-0.603056329566425, -0.999192946437536, 0.00282420705837356, 
-0.138063379339347), V6 = c(-1.33316658650733, -0.603056329566425, 
-0.999192946437536, 0.00282420705837356, -0.138063379339347, 
-1.57598823020269)), .Names = c("V1", "V2", "V3", "V4", "V5", 
"V6"))

COL03 <- structure(list(LONGITUDE = c(52.5, 52.5, 52.5, 52.5, 52.5, 52.5
), LATITUDE = c(-2.5, -2.5, -2.5, -2.5, -2.5, -2.5), DATE_START = structure(c(1358812800, 
1358899200, 1358985600, 1359072000, 1359158400, 1359244800), class = c("POSIXct", 
"POSIXt")), DATE_END = structure(c(1359417600, 1359504000, 1359590400, 
1359676800, 1359763200, 1359849600), class = c("POSIXct", "POSIXt"
)), FLAG = c(4, 4, 4, 4, 4, 4)), .Names = c("LONGITUDE", "LATITUDE", 
"DATE_START", "DATE_END", "FLAG"), row.names = c(NA, 6L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

我希望这可以帮到你

'data.frame':   6 obs. of  2 variables:
 $ COl_1: Factor w/ 6 levels "-0.0431597784900261 -0.518148142834806 -0.237032580263406 -0.920434206514568 -0.95436194682491 -0.556922703189482",..: 1 3 2 4 5 6
 $ col_2: Factor w/ 6 levels "-0.232516232554677 0.237972180098397 -0.988223009354951 -1.33316658650733 -0.603056329566425",..: 6 1 5 2 3 4

你得到一个包含两列和六行的数据框

{{1}}