R Language Processing population information for 1975-2011 years

Source: Internet
Author: User

Data for 1975-2011.

1) Which countries are the most populous each year? How many are there?

2) Statistics of the average population growth rate of 1975-2011 years in each country

3) Statistics of the 10 countries with the highest annual population

4) Statistics of the 10 countries with the lowest annual population

5) in conjunction with the classification of the continent's language, please obtain the following results

5.1) which continent has the largest population and which continent has the fewest population?

Population rankings for the top 3 countries in each continent

5.2) which language has the largest population in the country?

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 Arab Ia "," Singapore "," Tajikistan "," Thailand "," Turkmenistan "," Uzbekistan "," Yemen ",
" Bangladesh "," Georgia "," India " , "Jordan", "North Korea", "South Korea", "Lao", "Lebanon", "Maldives", "Mongolia",
"Philippines", "Sri Lanka", "timor- Leste "," Turkey "," Arab Emirates "," Brunei "," China "," Hong Kong, China ",
" Kyrgyz Republic "," Macao, China "," Syr Ia "," 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 "," U Nited 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",
"states", "Virgin Islands (U.S.)")

Oceania<-c ("Australia", "Kiribati", "New Caledonia", "New Zealand", "Palau", "Papua New Guinea", "Solomon Islands", "Tu Valu ",
"American Samoa", "Fiji", "French Polynesia", "Guam", "Marshall Islands", "Northern Mariana Islands", "Samoa", "Tonga", "V Anuatu ",
"Micronesia, the 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 ("Population of Asia", "Population of Europe", "population of North America", "Population of South America", "Population of Africa", "Population of Oceania", "\ 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", "Population", as[x], "\ n")
}
for (x in order (af,decreasing=true) [1:3]) {
Cat (af_i[x], "\ T", "Population", af[x], "\ n")
}
for (x in order (eu,decreasing=true) [1:3]) {
Cat (eu_i[x], "\ T", "Population", eu[x], "\ n")
}
for (x in order (sa,decreasing=true) [1:3]) {
Cat (sa_i[x], "\ T", "Population", sa[x], "\ n")
}
for (x in order (naa,decreasing=true) [1:3]) {
Cat (naa_i[x], "\ T", "Population", naa[x], "\ n")
}
for (x in order (oc,decreasing=true) [1:3]) {
Cat (oc_i[x], "\ T", "Population", oc[x], "\ n")
}

I didn't think there were no code tips for the R language. Here the most troublesome is the fifth question, the data to climb, to the Baidu Encyclopedia also has a data.cn website, climb, but still left 50 few climb out, in the heart very uncomfortable.

Let's pay attention to something. 1. Be aware of the working directory, otherwise you cannot read the CSV file.

2. Because the country name is read in the form of a factor, it has to be converted using As.character ().

It feels like these two things need attention, this thing is not difficult, but the fifth question is too cumbersome.

R Language Processing population information for 1975-2011 years

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.