temp_F <- c(35, 88, 42, 84, 81, 30)Classwork 4
R Basics I
Question 1.
- In R, the object
state.nameis available without loading any additional packages.
- Write R code to assign
state.nameto a new variable calledUS_states.
Example: calling state.name in R
Answer:
Question 2.
Write an R code to create a numeric vector named numbers containing the integers from 10 to 50.
Answer:
Question 3.
The temp_F vector contains the average high temperatures in January for the following cities: Seoul, Lagos, Paris, Rio de Janeiro, San Juan, and Rochester.
Create a new vector named temp_C that stores the converted Celsius temperatures. Below is the conversion formula:
\[ C = \frac{5}{9}\times(F - 32) \]
Answer:
Question 4.
Write an R code to assign the string βHello, World!β to a variable named greeting and display its value on the Console.
Answer:
Question 5.
Write an R code to convert the character vector char_vec <- c("1", "2", "3", "4") into a numeric vector named num_vec.
char_vec <- c("1", "2", "3", "4")Answer:
Question 6.
- Write an R code to concatenate two character vectors,
first_names <- c("John", "Jane")andlast_names <- c("Doe", "Smith"), to create a vectorfull_namescontaining the full names (e.g., βJohn Doeβ, βJane Smithβ) using thestr_c()function for vectorized character operations.- Note that the
str_c()function is provided by thestringrpackage, which is one of the packages in thetidyverse.
- Note that the
first_names <- c("John", "Jane")
last_names <- c("Doe", "Smith")Answer: