<- c(35, 88, 42, 84, 81, 30) temp_F
Classwork 4
R Basics I
Question 1.
- In R, the object
state.name
is available without loading any additional packages.
- Write R code to assign
state.name
to 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
.
<- c("1", "2", "3", "4") char_vec
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_names
containing 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 thestringr
package, which is one of the packages in thetidyverse
.
- Note that the
<- c("John", "Jane")
first_names <- c("Doe", "Smith") last_names
Answer: