In this exercise, you will work on implementing various data structures in R.
Create a vector using vec1 <- c(1L, 2L, 3L). What type of vector is this? Verify your answer using typeof(vec1).
Run the following code: vec2 <- as.numeric(vec1). Compare vec1 and vec2 using typeof() and object.size(). What are the differences?
Run the code: vec2 <- vec2 + c(1, 1.5, 1.99). Before checking the output, what is the result of this line of code?
Coerce vec2 to integer-type. What happens to non-integers?
Create another vector vec3 and assign the values "1L", "2L", "3L". What type of vector is this? Verify using typeof(). Coerce this to a numeric vector.
Open a new R script to write and save your code. You will need to re-use these results for Exercise 3!
Create vectors using c() with the following attributes.
A vector, name, with 10 names of your choosing. What type of vector is this?
A vector, female, with TRUEs and FALSEs indicating the sex of the people in your name vector. What type of vector is this? What is another way we could represent this information?
A vector, edu, indicating the highest degree of education completed for the people in your name vector. Use "HS" for high school, "BS" for a bachelor’s degree, "MS" for master’s, and "PhD" for doctorate.
A vector, salary, indicating the salary in 1,000s of dollars for the people in your name vector.
Run the following code to create a data.frame, data.
data <- data.frame(name = name,
female = female,
edu = edu,
salary = salary)