0
組
通過休息和出現計數砍我有一個數據幀,看起來像這樣:該城市屬於的R - 由
dat <- structure(list(Geocode = c("1100015", "1100023", "1100031", "1100049",
"1100056", "1100064", "1100072", "1100080", "1100098", "1100106",
"1100114", "1100122", "1100130", "1100148", "1100155", "1100189",
"1100205", "1100254", "1100262", "1100288", "1100296", "1100304",
"1100320", "1100338", "1100346", "1100379", "1100403", "1100452",
"1100502", "1100601"), Location = c("Alta Floresta D'oeste, RO",
"Ariquemes, RO", "Cabixi, RO", "Cacoal, RO", "Cerejeiras, RO",
"Colorado Do Oeste, RO", "Corumbiara, RO", "Costa Marques, RO",
"Espigo D'oeste, RO", "Guajar-Mirim, RO", "Jaru, RO", "Ji-Paran, RO",
"Machadinho D'oeste, RO", "Nova Brasilndia D'oeste, RO", "Ouro Preto Do Oeste, RO",
"Pimenta Bueno, RO", "Porto Velho, RO", "Presidente Mdici, RO",
"Rio Crespo, RO", "Rolim De Moura, RO", "Santa Luzia D'oeste, RO",
"Vilhena, RO", "So Miguel Do Guapor, RO", "Nova Mamor, RO", "Alvorada D'oeste, RO",
"Alto Alegre Dos Parecis, RO", "Alto Paraso, RO", "Buritis, RO",
"Novo Horizonte Do Oeste, RO", "Cacaulandia, RO"), Region = c("Norte",
"Norte", "Norte", "Norte", "Norte", "Norte", "Norte", "Norte",
"Norte", "Norte", "Sul", "Sul", "Sul", "Sul", "Sul",
"Sul", "Sul", "Sul", "Sul", "Sul", "Nordeste", "Nordeste",
"Nordeste", "Nordeste", "Nordeste", "Nordeste", "Nordeste", "Nordeste", "Nordeste",
"Nordeste"), Population = c(25578L, 104401L, 6355L, 87226L, 17986L,
18817L, 8842L, 16651L, 32385L, 46632L, 55738L, 130419L, 37167L,
21592L, 39924L, 37512L, 502748L, 22557L, 3750L, 56242L, 8532L,
91801L, 23933L, 27600L, 17063L, 13940L, 20210L, 37838L, 10276L,
6367L)), .Names = c("Geocode", "Location", "Region", "Population"
), row.names = c(NA, 30L), class = "data.frame")
這表明一些城市的人口,以及該地區。
我需要將人口分爲兩部分(breaks=c(0,50000,100000)
),然後根據整體(所有地區)的休息時間以及按地區分開來查找城市的數量。
所得數據幀應該是這樣的(無規,假設值):
Class Region Count
[0-50000] Norte 7
[50000-100000] Norte 3
[>100000] Norte 0
[0-50000] Sul 5
[50000-100000] Sul 4
[>100000] Sul 1
[0-50000] Nordeste 4
[50000-100000] Nordeste 5
[>100000] Nordeste 1
[0-50000] All 16
[50000-100000] All 12
[>100000] All 2
任何幫助理解。
或者,在創建'Class'後,bind_rows(count(dat,Region,Class),count(dat,Class,Region =「all」))'會做。 – jazzurro
@jazzurro很棒:-)謝謝 – Wen
不客氣。 :) – jazzurro