Question: # Function 1 : Create a function called readStates: #Step 1 : Create a function ( named readStates ) to read a CSV file into

# Function 1: Create a function called "readStates":
#Step 1: Create a function (named readStates) to read a CSV file into R: within the Function 1
#Q1. You need to read a URL, not a local file to your computer.
#Q2. The file is a dataset on state populations (within the United States).
#Step 2: Clean the dataframe: within Function 1
#Q3. Note the issues that need to be fixed (removing columns, removing rows, changing column names).
#Q4. Within your function, make sure there are 51 rows (one per state + the district of Columbia). Make sure there are only 5 columns with the columns having the following names (stateName, Census, Estimates, Pop2010, Pop2011).
#Q5. Make sure the last four columns are numbers (i.e. not strings).
#Step 3: Store and explore the dataset: outside of Function 1
#Q6. Store the dataset into a dataframe, called dfStates.
# When you run the following, it should print a clean dataframe. Please include the output of "dfStates" in the compiled file by running dfStates as below.
dfStates <- readStates(urlToRead)
dfStates
#Q7. Test your dataframe by calculating the mean for the 2011 data, by doing (include your output):
mean(dfStates$Pop2011)
# You should get an answer of6,109,645
#Step 4: Find the state with the highest population: outside the Function 1
#Q8. Based on the 2011 data, what is the population of the state with the highest population? What is the name of that state, and what is the value of the population?
#Q9. Sort the data, in increasing order, based on the 2011 data.
# Function 2: Create a function called "Distribution"
#Step 5: Explore the distribution of the states: You need to create a new function called "Distribution"
#Q10. You will write a function to calculate percentage of states that have population that is lower than the average. The function (function name: "Distribution") takes two parameters. The first is a vector and the second is a number. For example, Distribution <- function(vector, number).
# The function will return the percentage of elements within the vector that is less than the number (i.e. cumulative distribution below the value provided).
# (1) Think about this: You only keep the elements within the vector that are less than the number, and store the number of eligible elements into the variable "count". Populate XXXX to complete this line of code:
count <- length(vector[XXXX])
# (2) Then, you will calculate the percentage and return the results. Populate XXXX to complete this line of code:
return((count/XXXX)*100)
# (3) Test the function with the vector dfStates$Pop2011, and the mean of dfStates$Pop2011.*** you should get 66.66667 as a result.
table with row headers in column A and column headers in rows 3 through 4.(leading dots indicate sub-parts) Table 1. Annual Estimates of the Population for the United States, Regions, States, and Puerto Rico: April 1,2010 to July 1,2011 Geographic Area 1-Apr-10 Population Estimates (as of July 1) Census Estimates Base 20102011 United States ######## ######## ######## ######## Northeast ######## ######## ######## ######## Midwest ######## ######## ######## ######## South ######## ######## ######## ######## West ######## ######## ######## ######## .Alabama 4,779,7364,779,7354,785,4014,802,740.Alaska 710,231710,231714,146722,718.Arizona 6,392,0176,392,0136,413,1586,482,505.Arkansas 2,915,9182,915,9212,921,5882,937,979.California ######## ######## ######## ######## .Colorado 5,029,1965,029,1965,047,6925,116,796.Connecticut 3,574,0973,574,0973,575,4983,580,709.Delaware 897,934897,934899,792907,135.District of Columbia 601,723601,723604,912617,996.Florida ######## ######## ######## ######## .Georgia 9,687,6539,687,6609,712,1579,815,210.Hawaii 1,360,3011,360,3011,363,3591,374,810.Idaho 1,567,5821,567,5821,571,1021,584,985.Illinois ######## ######## ######## ######## .Indiana 6,483,8026,483,8006,490,6226,516,922.Iowa 3,046,3553,046,3503,050,2023,062,309.Kansas 2,853,1182,853,1182,859,1432,871,238.Kentucky 4,339,3674,339,3624,347,2234,369,356.Louisiana 4,533,3724,533,3724,545,3434,574,836.Maine 1,328,3611,328,3611,327,3791,328,188.Maryland 5,773,5525,773,5525,785,6815,828,289.Massachusetts 6,547,6296,547,6296,555,4666,587,536.Michigan 9,883,6409,883,6359,877,1439,876,187.Minnesota 5,303,9255,303,9255,310,6585,344,861.Mississippi 2,967,2972,967,2972,970,0722,978,512.Missouri 5,988,9275,988,9275,995,7156,010,688.Montana 989,415989,415990,958998,199.Nebraska 1,826,3411,826,3411,830,1411,842,641.Nevada 2,700,5512,700,5512,704,2832,723,322.New Hampshire 1,316,4701,316,4721,316,8071,318,194.New Jersey 8,791,8948,791,8948,799,5938,821,155.New Mexico 2,059,1792,059,1802,065,9132,082,224.New York ######## ######## ######## ######## .North Carolina 9,535,4839,535,4759,560,2349,656,401.North Dakota 672,591672,591674,629683,932.Ohio ######## ######

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!