日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

R语言处理1975-2011年的人口信息

發(fā)布時(shí)間:2024/6/30 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言处理1975-2011年的人口信息 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1975-2011年的數(shù)據(jù)中。

1)分別統(tǒng)計(jì)每年人口最多的國家是哪個(gè)?有多少

2)統(tǒng)計(jì)出各個(gè)國家的1975-2011年的平均人口增長率

3)統(tǒng)計(jì)每年人口最多的十個(gè)國家

4)統(tǒng)計(jì)出每年人口最少的十個(gè)國家

5)結(jié)合洲的語言的分類,請得出如下結(jié)果

? ?5.1)哪個(gè)洲的人口最多?哪個(gè)洲的人口最少?

? ?每個(gè)洲的前3個(gè)國家人口排名

? ?5.2)哪種語言的國家人口最多?

librery(xlsx)

data<-read.xlsx("urbanpop.xlsx",sheet_index=3)
i<-0

for(dt in data){
if(i==0){
i<-2
next}
else{
index<-which(dt == max(dt,na.rm=TRUE))
cat(as.character(data$country[index]),dt[index],"\n")

}

}

data$country[1]

(data$X2011[1]-data$X1975[1])^(1/(2011-1975))-1

paste(((data$X2011[1]-data$X1975[1])^(1/(2011-1975))-1)*100,"%",sep="")

for(i in 1:209){
cat(as.character(data$country[i]),"\t",paste(((data$X2011[i]-data$X1975[i])^(1/(2011-1975))-1)*100,"%",sep=""),"\n")

}

i<-0
year<-1975
for(dt in data){
if(i==0){
i<-2
next}
else{
countrys_id <- order(dt,decreasing=TRUE)[1:10]
cat(year,"\t")
for(index in countrys_id){
cat(as.character(data$country[index]),"\t")
}
year=year+1
cat("\n")

}

}


i<-0
year<-1975
for(dt in data){
if(i==0){
i<-2
next}
else{
countrys_id <- order(dt,decreasing=FALSE)[1:10]
cat(year,"\t")
for(index in countrys_id){
cat(as.character(data$country[index]),"\t")
}
year=year+1
cat("\n")

}

}

?

?

Asian<-c("Afghanistan", "Armenia", "Azerbaijan", "Bahrain", "Bhutan", "Cambodia", "Indonesia",
"Iran", "Iraq", "Israel", "Japan", "Kazakhstan", "Kuwait", "Malaysia", "Myanmar", "Nepal", "Oman",
"Pakistan", "Qatar", "Saudi Arabia", "Singapore", "Tajikistan", "Thailand", "Turkmenistan", "Uzbekistan", "Yemen",
"Bangladesh", "Georgia", "India", "Jordan", "North Korea", "South Korea", "Lao", "Lebanon", "Maldives", "Mongolia",
"Philippines", "Sri Lanka", "Timor-Leste", "Turkey", "United Arab Emirates","Brunei", "China", "Hong Kong, China",
"Kyrgyz Republic", "Macao, China", "Syria", "Vietnam")

Europe<-c("Albania", "Austria", "Belgium", "Bosnia and Herzegovina", "Bulgaria", "Croatia",
"Cyprus", "Czech Republic", "Denmark", "Estonia", "France", "Germany", "Greece", "Hungary", "Latvia",
"Liechtenstein", "Lithuania", "Malta", "Netherlands", "Norway", "Portugal", "Russia", "Serbia", "Slovenia", "Sweden", "Ukraine",
"Andorra","Channel Islands", "Faeroe Islands", "Finland", "Iceland", "Ireland", "Isle of Man", "Italy", "Luxembourg", "Macedonia, FYR",
"Moldova", "Monaco", "Montenegro", "Poland", "Romania", "San Marino", "Slovak Republic", "Spain", "Switzerland", "United Kingdom")

Afrain<-c("Algeria", "Angola", "Benin", "Botswana", "Burkina Faso", "Burundi", "Chad", "Comoros",
"Cote d'Ivoire", "Djibouti", "Eritrea", "Ethiopia", "Guinea", "Kenya", "Lesotho", "Liberia", "Libya",
"Mauritania", "Mauritius", "Mozambique", "Namibia", "Niger", "Rwanda", "Sao Tome and Principe", "Seychelles",
"Sierra Leone", "Swaziland", "Tanzania", "Uganda", "Zambia", "Zimbabwe", "South Sudan","Cameroon",
"Central African Republic", "Egypt", "Equatorial Guinea", "Gabon", "Gambia", "Ghana", "Guinea-Bissau",
"Madagascar", "Malawi", "Mali", "Morocco", "Nigeria", "Senegal", "Somalia", "South Africa", "Sudan", "Togo","Tunisia",
"Cape Verde", "Congo, Dem. Rep.", "Congo, Rep.")

SouthAmerican<-c("Argentina", "Guyana", "Paraguay", "Peru", "Suriname", "Uruguay", "Venezuela","Brazil", "Chile",
"Colombia", "Ecuador","Aruba","Belarus","Bolivia")

NorthAmerican<-c("Antigua and Barbuda", "Bahamas", "Barbados", "Canada", "Greenland", "Grenada",
"Guatemala", "Honduras", "Jamaica", "Nicaragua", "St. Kitts and Nevis", "Trinidad and Tobago","Belize",
"Bermuda", "Cayman Islands", "Costa Rica", "Cuba", "Dominica", "Dominican Republic", "El Salvador",
"Haiti", "Mexico", "Panama", "Puerto Rico", "St. Lucia", "St. Vincent and the Grenadines", "Turks and Caicos Islands",
"United States", "Virgin Islands (U.S.)")

Oceania<-c("Australia", "Kiribati", "New Caledonia", "New Zealand", "Palau", "Papua New Guinea", "Solomon Islands", "Tuvalu",
"American Samoa", "Fiji", "French Polynesia", "Guam", "Marshall Islands", "Northern Mariana Islands", "Samoa", "Tonga", "Vanuatu",
"Micronesia, Fed. Sts.")

?

AS_number<-0
AF_number<-0
EU_number<-0
SA_number<-0
NA_number<-0
OC_number<-0
other_number<-0
index<-1
for(country in data$country){
if(country %in% Asian){
AS_number= AS_number+data$X2011[index]
}else if(country %in% Europe){
EU_number = EU_number+data$X2011[index]
}else if(country %in% Afrain){
AF_number= AF_number+data$X2011[index]
}else if(country %in% SouthAmerican){
SA_number= SA_number+data$X2011[index]
}else if(country %in% NorthAmerican){
NA_number= NA_number+data$X2011[index]
}else if(country %in% Oceania){
OC_number= OC_number+data$X2011[index]
}else{
other_number= other_number +data$X2011[index]
}
index=index+1
}

cat("亞洲人口數(shù)","歐洲人口數(shù)","北美洲人口數(shù)","南美洲人口數(shù)","非洲人口數(shù)","大洋洲人口數(shù)","\n")
population<-c(AS_number,EU_number,NA_number,SA_number,AF_number,OC_number)
sort_pl<-order(population)
sort_pl


AS<-c()
AF<-c()
EU<-c()
SA<-c()
NAA<-c()
OC<-c()
AS_I<-c()
AF_I<-c()
EU_I<-c()
SA_I<-c()
NAA_I<-c()
OC_I<-c()
index<-1
dt_2011<-data$X2011
for(country in data$country){
if(country %in% Asian){
AS_I=c(AS_I,country)
AS=c(AS,dt_2011[index])
}else if(country %in% Europe){
EU_I=c(EU_I,country)
EU=c(EU,dt_2011[index])
}else if(country %in% Afrain){
AF_I=c(AF_I,country)
AF=c(AF,dt_2011[index])
}else if(country %in% SouthAmerican){
SA_I=c(SA_I,country)
SA=c(SA,dt_2011[index])
}else if(country %in% NorthAmerican){
NAA_I=c(NAA_I,country)
NAA=c(NAA,dt_2011[index])
}else if(country %in% Oceania){
OC_I=c(OC_I,country)
OC=c(OC,dt_2011[index])
}else{
print(country)
}
index=index+1
}
for(x in order(AS,decreasing=TRUE)[1:3]){
cat(AS_I[x],"\t","人口數(shù)",AS[x],"\n")
}
for(x in order(AF,decreasing=TRUE)[1:3]){
cat(AF_I[x],"\t","人口數(shù)",AF[x],"\n")
}
for(x in order(EU,decreasing=TRUE)[1:3]){
cat(EU_I[x],"\t","人口數(shù)",EU[x],"\n")
}
for(x in order(SA,decreasing=TRUE)[1:3]){
cat(SA_I[x],"\t","人口數(shù)",SA[x],"\n")
}
for(x in order(NAA,decreasing=TRUE)[1:3]){
cat(NAA_I[x],"\t","人口數(shù)",NAA[x],"\n")
}
for(x in order(OC,decreasing=TRUE)[1:3]){
cat(OC_I[x],"\t","人口數(shù)",OC[x],"\n")
}

?

沒想到?jīng)]有R語言的代碼貼士。這里面最麻煩的是第五題,數(shù)據(jù)要自己去爬,去了百度百科還有個(gè)data.cn的網(wǎng)站,爬,但是還剩下50幾個(gè)爬不出來,心里很難受。

說下注意的東西吧。1.是工作目錄得注意,不然讀取不到csv文件。

2.因?yàn)閲颐Q是以因子的形式讀取出來的,因此得使用as.character()來轉(zhuǎn)換一下。

感覺就這兩點(diǎn)東西需要注意,這東西不難,但是第五題太繁瑣。

轉(zhuǎn)載于:https://www.cnblogs.com/ke-T3022/p/7811057.html

總結(jié)

以上是生活随笔為你收集整理的R语言处理1975-2011年的人口信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。