У меня есть несколько данных, связанных с идентификатором периода, которые соответствуют периоду, связанному с датой.
Я хотел бы создать автоматизированную c систему для привязки каждого блока, связанного с идентификатором группы. Это просто пример моих данных, у меня есть другие местоположения, связанные с периодами, и множество других погодных переменных /
Ниже приведен пример моих данных:
> weatherPer =structure(list(periods = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1,
2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Year_Loc = structure(c(1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L,
9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 12L, 12L,
12L, 12L), .Label = c("Auzay-2006", "Brain sur lâ\200\231Authion-2016",
"Brain sur lâ\200\231Authion-2017", "Brain sur lâ\200\231Authion-2018",
"Brain sur lâ\200\231Authion-2019", "Campagne-2005", "Campagne-2006",
"Campagne-2007", "Campagne-2008", "Campagne-2009", "Campagne-2010",
"Campagne-2015", "Campagne-2016", "Campagne-2017", "Campagne-2018",
"Campagne-2019", "Casalmorano-2013", "Casalmorano-2016", "Casalmorano-2017",
"Castelsarrasin-2018", "Chapaeva-2019", "Conselice-2017", "Endoufielle-2016",
"Endoufielle-2017", "Genivolta-2014", "Izano-2018", "Izano-2019",
"Köröstarcsa-2015", "Köröstarcsa-2016", "Krasnogvardeyskoe-2019",
"La Bastide-Savès-2004", "La Bastide-Savès-2005", "La Bastide-Savès-2006",
"La Bastide-Savès-2007", "La Daguenière-2012", "La Daguenière-2013",
"La Daguenière-2014", "La Daguenière-2015", "Le Langon-2003",
"Le Langon-2004", "Le Langon-2005", "Lombez-2001", "Lombez-2002",
"Lombez-2003", "Meilhan-2001", "Meilhan-2003", "Meilhan-2004",
"Mezoberény-2017", "Mezoberény-2018", "Molosso-2014", "Monferran-Savès-2008",
"Monferran-Savès-2009", "Moscazzano-2016", "Moscazzano-2018",
"Moscazzano-2019", "Noilhan-2014", "Noilhan-2015", "Pontonx-2011",
"Pontonx-2012", "Pontonx-2014", "Pouille-2007", "Samatan-2011",
"Samatan-2012", "Samatan-2013", "Sauvimont-2019", "Ste Hermine-2001",
"Thiré-2010", "Thiré-2011", "Turkeve-2010", "Turkeve-2011",
"Turkeve-2012", "Turkeve-2013", "Turkeve-2014", "Turkeve-2015",
"Turkeve-2016", "Turkeve-2017", "Turkeve-2018", "Turkeve-2019"
), class = "factor"), Dewpoint.Temperature.max = c(24.82, 24.31,
23.99, 23.33, 25.65, 24.42, 23.46, 22.19, 24.61, 24.29, 23.75,
23.64, 24.33, 23.67, 23.56, 22.66, 24.89, 24.45, 23.88, 23.83,
24.85, 24.35, 23.5, 23.58, 24.72, 24.37, 23.93, 23.23, 25.02,
24.52, 22.96, 22.78, 24.15, 23.21, 22.68, 22.34, 24.33, 24.21,
23.84, 23.01, 24.96, 24.41, 23.43, 23.01, 25.21, 24.78, 23.75,
23.79), Temperature.max = c(28.92, 28.09, 27.42, 27.2, 28.67,
27.31, 26.25, 24.41, 28.06, 27.28, 27.08, 26.46, 27.15, 26.32,
26.05, 26.11, 28.28, 26.97, 26.27, 25.95, 28.43, 27.92, 26.67,
26.55, 28.46, 27.77, 27.18, 27.02, 28.52, 28.21, 27.1, 26.06,
27.56, 26.47, 26.3, 25.58, 27.33, 27.44, 27.12, 25.93, 28.29,
27.33, 26.77, 25.55, 28.9, 27.81, 27.01, 26.7), Vapor.Pressure.Deficit.max = c(10.687021,
9.631794, 8.979559, 12.584732, 11.020079, 9.380499, 6.795023,
5.8055077, 10.550922, 9.470808, 10.791325, 11.422356, 8.21545,
8.206741, 9.171038, 10.28149, 9.686199, 6.392605, 7.2071304,
7.353756, 11.496166, 11.108919, 9.8492565, 8.664175, 10.241858,
9.6217575, 9.886763, 10.448376, 9.981283, 11.2334175, 13.815418,
8.470074, 9.944298, 9.327803, 11.135061, 7.913679, 12.109056,
9.2556095, 10.473219, 9.0791, 9.969273, 9.392576, 9.093296, 7.923086,
11.310198, 9.246443, 9.706051, 9.757435), Wind.Speed.max = c(5.6849194,
6.484783, 8.015649, 8.518107, 9.463871, 8.034819, 7.592716, 7.3360224,
6.2443833, 7.663488, 7.987683, 7.7891116, 7.131077, 8.027853,
7.293194, 8.160896, 6.6898775, 7.853842, 7.0723906, 7.2770677,
6.583669, 7.4978127, 8.006221, 8.029595, 6.258702, 8.492785,
8.090327, 8.9169445, 6.9531293, 8.830892, 8.904387, 7.870207,
7.2118154, 8.53615, 8.329502, 8.405386, 6.9123783, 8.136524,
9.013042, 8.385395, 7.2226667, 8.086524, 8.451847, 7.629467,
8.390397, 9.166902, 8.754542, 7.8220797), Cloud.Cover.Total.mean = c(21.6705552666667,
24.802344375, 35.3500005333333, 26.181511375, 28.456863, 27.5972222222222,
28.9064821111111, 26.4129642777778, 25.1023805714286, 30.0522227333333,
32.2083346, 29.1186114666667, 26.6502785333333, 25.3466667333333,
29.8933342, 24.8361118, 24.7013881666667, 24.7849367692308, 25.5059030833333,
29.222758, 33.8592948461538, 29.7266027692308, 31.902885, 30.8227573076923,
23.2564103076923, 29.7651781428571, 29.3422613571429, 28.9532741428571,
29.3786112666667, 33.2297226666667, 25.7091675333333, 27.2164065625,
37.16000065, 29.0987506, 33.0527089, 27.8439584, 24.0283332666667,
36.0616664666667, 26.6388894666667, 26.0858338666667, 28.276786,
27.2019451333333, 29.3044452, 19.6738889333333, 22.4424480625,
25.0080889411765, 24.6013021875, 24.5941178235294), Dewpoint.Temperature.mean = c(23.8762221333333,
23.4136724375, 23.1081674666667, 21.8481506875, 23.5936522941176,
22.8560645555556, 22.3810187222222, 21.2194674444444, 23.6746725,
23.2300559333333, 22.6978884666667, 21.9656385333333, 23.5449448,
22.9195002, 22.5098344, 21.7956943333333, 23.6780560833333, 23.6903846923077,
23.0403119166667, 23.1599683076923, 23.7525644615385, 22.9774354615385,
22.5111217692308, 22.0802245384615, 23.8259936923077, 23.6056247857143,
22.8909821428571, 21.5979167857143, 24.0113888666667, 23.1943053333333,
22.0449716666667, 21.989557, 23.14185435, 22.10529135, 21.48256205,
21.18364525, 22.8545552666667, 23.5222784, 22.307806, 21.8091116666667,
24.0137797142857, 23.3254436, 22.5024446, 21.7409172666667, 24.0527341875,
23.3409315294118, 22.7526048125, 22.1225985294118), Pressure.mean = c(1010.95196,
1012.383083125, 1012.24418466667, 1014.710431875, 1012.83724294118,
1013.90580166667, 1014.17571888889, 1014.73749166667, 1012.34075,
1012.398044, 1012.91250266667, 1013.746396, 1011.720292, 1013.600556,
1012.87333666667, 1014.77361466667, 1011.04514083333, 1012.81733384615,
1012.87810083333, 1012.74068230769, 1011.01218769231, 1012.37469769231,
1013.71220692308, 1014.54871538462, 1012.03207384615, 1012.76129285714,
1012.77921, 1015.22201357143, 1011.19640733333, 1011.18028866667,
1013.49386133333, 1014.96224875, 1011.7522905, 1013.816709, 1014.201673,
1014.2712105, 1012.163322, 1013.25557933333, 1013.90890266667,
1015.02249, 1012.06099642857, 1013.61306933333, 1013.49166666667,
1014.40390933333, 1012.31040625, 1011.79900411765, 1014.14636875,
1015.40442), Relative.Humidity.mean = c(80.4391176, 83.1505465625,
83.1818152666667, 80.61810925, 81.5311527647059, 81.7008705,
85.133456, 86.0116727777778, 82.0734179285714, 81.6275006666667,
81.363433, 81.1003484666667, 84.3441953333333, 85.7540380666667,
84.6901137333333, 84.078286, 82.4465179166667, 86.464035, 85.2495825,
86.9968460769231, 83.0805199230769, 80.1526246153846, 80.9706803076923,
81.4566846923077, 80.2394810769231, 83.874552, 82.3113892142857,
78.3532723571429, 81.7885049333333, 80.4320084, 80.0532001333333,
82.4779069375, 84.9907835, 81.958613, 80.2184465, 80.59267855,
81.2794322666667, 85.3465956666667, 79.5406666, 81.9668526666667,
83.1170027857143, 83.0287677333333, 82.5559213333333, 82.8191025333333,
82.1219480625, 81.7881238823529, 80.705515375, 80.8482061176471
)), row.names = c(NA, 48L), class = "data.frame")
Вот что я делаю сейчас:
for (i in (unique(weatherPer$periods))){
if (i == 1){
weatherWide = filter(weatherPer,periods == i)
}
else{
DF2 = filter(weatherPer,periods == i)
colnames(DF2) = paste(colnames(DF2),paste0("sub_per.",i), sep = ".")
weatherWide = cbind(weatherWide,DF2[,-c(1,2)])
}
И глобально, что я хотел бы сделать:
Я просто думаю, что мой код не "эффективен" Есть ли другой способ сделать это?