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.
Reviews
There are no reviews yet.