Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW2 #161

Open
wants to merge 5 commits into
base: gh-pages
Choose a base branch
from
Open

HW2 #161

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ _site
.RData
.Rhistory
Thumbs.db
<<<<<<< HEAD
.Rproj.user
||||||| merged common ancestors
=======
.Rproj.user

## Rproj is seriously annoying. Sorry.
*.Rproj
*.Rbuildignore
.Rproj.user
*cache
>>>>>>> upstream/gh-pages
54 changes: 54 additions & 0 deletions hw2/_posts/2014-11-19-hw2-Liangquan-Zhou-lz2377.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "HW2"
author: "Liangquan Zhou lz2377"
date: "Wednesday, November 19, 2014"
output: html_document
---


## Now let's finish today's hw(2014-09-18). First load sample data.

```{r, cache=TRUE}
setwd("C:/Liangquan Zhou/Study/2014 fall/data visualization/hw1")
sample_data= read.csv("sample_health_facilities.csv") # read the .csv file
```

1. Select all facilities located in the southern zones of Nigeria.

```{r, cache=TRUE}
new_data= subset(sample_data, zone %in% c("Southwest","Southeast","South-South"))
```

2. Incorporate the pop2006 column from the `lgas.csv` file into the new data.frame containing only those facilities located in Southern Nigeria. (Hint: your id column is `lga_id`)

```{r, cache=TRUE}
lgas= read.csv("lgas.csv", stringsAsFactors=T)
new_data= merge(new_data, lgas[c("lga_id","pop_2006")],by= "lga_id")
```

And we can use `str` to see the new dataset:
```{r}
str(new_data)
```

3. Calculate the total number of full time nurses and doctors for all health facilities in each state.
```{r, cache=TRUE}
tapply(new_data$num_doctors_fulltime, new_data$state,sum)
tapply(new_data$num_nurses_fulltime, new_data$state,sum)
```

4. Sort the resulting dataset by state population, in descending order.
```{r,cache=TRUE}
data1=subset(new_data,select=c(num_doctors_fulltime,num_nurses_fulltime,pop_2006,state))
data1$state=as.factor(as.character(data1$state))
result=data.frame(tapply(data1$num_doctors_fulltime, data1$state,sum),
tapply(data1$num_nurses_fulltime, data1$state,sum),
tapply(data1$pop_2006, data1$state,sum))
names(result)=c("num_doctors_fulltime","num_nurses_fulltime","pop_2006")
result=result[order(result$pop_2006),]
```

The result is:
```{r,cache=TRUE}
result
```
158 changes: 158 additions & 0 deletions hw2/_posts/2014-11-19-hw2-Liangquan-Zhou-lz2377.html

Large diffs are not rendered by default.