Question

Use the R package “UsingR” to download the data file (called “aid”) about monthly payment for...

Use the R package “UsingR” to download the data file (called “aid”) about monthly payment for federal program to R.

Use R code to check whether it is a vector or matrix. Then assign “payment” as a vector based on the payment amounts only by removing the names of the states.

Use the appropriate vector functions to rank, to sort, and to order the payment vector. Call these vectors as rank.payment, sorted.payment, and ordered.payment, Then use R code to make a dataframe (or table) out of these four vectors.

Use R code to save the dataframe or table in the text file called “table.txt” in your working directory.

Use R code to find the name of the states with highest and lowest payment.

Homework Answers

Answer #1

library(UsingR)

data(aid) #read data

#check vector or matrix
if(is.vector(aid)){
print("Vector")
} else if(is.matrix(aid)){
print("Matrix")
}

#remove names
payment <- unname(aid)

#rank, order, sort
rank.payment <- rank(payment)
ordered.payment<- payment[order(payment)]
sorted.payment<-sort(payment)

#create dataframe
tb <-data.frame(col1 = payment, col2= rank.payment, col3= sorted.payment, col4 = ordered.payment)

#write dataframe
write.table(tb,"table.txt",sep="\t",row.names=FALSE)

#lowest payment from rank ordering
attributes(aid)$names[match(1, rank.payment)]

#highest payment from rank ordering
attributes(aid)$names[match(51, rank.payment)]

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use R to do each of the following. Use R code instructions that are as general...
Use R to do each of the following. Use R code instructions that are as general as possible, and also as efficient as possible. Use the Quick-R website for help on finding commands. 1. Enter the following values into a data vector named Dat: 45.4 44.2 36.8 35.1 39.0 60.0 47.4 41.1 45.8 35.6 2. Calculate the difference between the 2nd and 7th entries of this vector using only reference indices. 3. Calculate the median of Dat. 4. Sort the...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how...
Delta airlines case study Global strategy. Describe the current global strategy and provide evidence about how the firms resources incompetencies support the given pressures regarding costs and local responsiveness. Describe entry modes have they usually used, and whether they are appropriate for the given strategy. Any key issues in their global strategy? casestudy: Atlanta, June 17, 2014. Sea of Delta employees and their families swarmed between food trucks, amusement park booths, and entertainment venues that were scattered throughout what would...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT