AMS597Â
- Consider the following weights 60, 72, 34, 56, 87, 80, 89, 95, 76, 28, 48, 59. Use the R script to finish the following questions
- Assign all these weights as vector âweightâ.
- Compute the mean of âweightâ and of the square of the weight.
- What is the length of the weight?
- How many weights are larger than 55?
- Output a vector of length equal to the length of weight, in which the element takes value âYesâ if the weight is larger than 55 and smaller than 85, and âNoâ otherwise.
- Using the following script, we can generate a 3Ă4 matrix tmp <- matrix(rnorm(12), 3, 4). Answer the following questions.
- Compute the sum of the first and third column.
- Compute the product of the first and third row.
- Show the dimension of the matrix.
- Use âcatâ function to output elements in the first row that are larger than 0.5.
- How would you check whether two vectors are the same if they may contain missing (NA) values?
- If x is a factor with n levels and y is a length n vector, what happens if you compute y[x]?
- Write your own function cal which takes in a vector and return the median of the vector. Do not use the built-in function median().
- Using the following script, we will generate a toy DNA sequence mydna <- paste(sample(c(âaâ,âtâ,âcâ,âgâ),1000,replace=T),collapse=ââ). Write a function that takes a string as a input, counts the number of âcgâ in the input string, and replace all âcgâ with âXYâ. Apply your function to mydna. (Do not use any special R packages.)
- Write a function which reads in the file from http://www.ams.sunysb.edu/~pfkuan/ Teaching/AMS597/Data/PhoneNumber.txt and output rows containing valid phone numbers from the file. Valid phone numbers take one of the following form:
c PF.Kuan
###-###-####
(###) ###-####
### ### ####
###.###.#### where # is a digit between 0-9.



