Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

R function explain cat function?

Use the R script to finish the following operations ( Explain question 3)

(1) Use ’rexp’ to generate 50 exponential random variables with rate 2, and store them in a vector called ’rand.vec’

(2) Turn the vector ’rand.vec’ into a 5x10 matrix with option ’byrow = T’, and assign the name ’rand.mat’ to the matrix.

(3) Use ’cat’ function to output the value of the elements in the 4th row of the matrix whose value is greater than 0.5.

My code:

rand.vec <- rexp(50, rate = 2)

rand.mat <- matrix(rand.vec, nrow = 5, byrow = T)

cat(rand.mat[4,rand.mat[4,]>0.5])

Can you explain the cat function and how the code "cat(rand.mat[4,rand.mat[4,]>0.5])" extracts elements in the 4th row of the matrix whose value is greater than 0.5.

thank you

There are no answers yet.
Be the first to answer this question.