Read the questions. At the bottom, you will find a link to the answers.
The Questions
First Set
You can find the answers here.
Second Set
You can find the answers here.
Third Set
1. If I have a data.frame df <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c(7, 8, 9))
...
c(4, 5, 6)
?1
?5
?df[, 3]
?df[1,]
?df[2, 2]
?2. What is the difference between a matrix and a dataframe?
3. If I concatenate a number and a character together, what will the class of the resulting vector be?
4. What if I concatenate a number and a logical?
5. What if I concatenate a number and NA
?
6. What is the difference between sapply
and lapply
? When should you use one versus the other? Bonus: When should you use vapply
?
7. What is the difference between seq(4)
and seq_along(4)
?
8. What is f(3)
where:
y <- 5 f <- function(x) { y <- 2; y^2 + g(x) } g <- function(x) { x + y }
Why?
9. I want to know all the values in c(1, 4, 5, 9, 10)
that are not in c(1, 5, 10, 11, 13)
. How do I do that with one built-in function in R? How could I do it if that function didn't exist?
10. Can you write me a function in R that replaces all missing values of a vector with the mean of that vector?
11. How do you test R code? Can you write a test for the function you wrote in #6?
12. Say I have...
fn(a, b, c, d, e) a + b * c - d / e
How do I call fn
on the vector c(1, 2, 3, 4, 5)
so that I get the same result as fn(1, 2, 3, 4, 5)
? (No need to tell me the result, just how to do it.)
13. dplyr <- "ggplot2" library(dplyr)
Why does the dplyr package get loaded and not ggplot2?
14. mystery_method <- function(x) { function(z) Reduce(function(y, w) w(y), x, z) } fn <- mystery_method(c(function(x) x + 1, function(x) x * x)) fn(3)
What is the value of fn(3)
? Can you explain what is happening at each step?
You can find the answers here.
Other R questions are posted here.
Related articles
Comment
I find some answers incomplete and/or misleading.
Good stuff, Thank you for posting this. Just some questions: Is there a typo in question 6? Did you mean 'comment' instead of 'command'? On question 7, 'save' function is a good option too. Also in the question 8, maybe it meant to be 'correlation' nor 'co-relation' as the answer refers to the cor() function.
© 2019 Data Science Central ® Powered by
Badges | Report an Issue | Privacy Policy | Terms of Service
You need to be a member of Data Science Central to add comments!
Join Data Science Central