1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
character_vec[2:3]
Gets the second and third elements of character_vec
logical_vec[-1]
Gets all the elements of logical_vec except the first
logical_vec[-c(1,2)]
All elements of logical_vec EXCEPT the first and second
students <- data.frame
Creating data frames named students
students$name
Acessing colum name in students data frame
students[["gpa"]]
Acessing colum gpa in students data frame
students[, "has_job"]
Acessing colm has_job in students data frame
getwd()
Check current working directory
list.files(".")
# List files in current directory
library(here)
Using the here package for robust path handling (always starts from project root)
How do you create a numeric vector called inflation_rates containing these values: 2.1, 3.4, 1.8, 4.2, 2.9. What is the result of inflation_rates[3]?
inflation_rates ← c(2.1, 3.4, 1.8, 4.2, 2.9). Result 1.8
Create a character vector called countries with elements: “Netherlands”, “Germany”, “France”, “Italy”. Use negative indexing to return all countries except “Germany” (the second element). Then get the same result using positive indexing.
countries <- c("Netherlands","Germany","France","Italy"). countries[-2]. countries[c(1,3,4)]
Given the vector x ← c(10, 20, 30, 40, 50), what does x[c(2,4)] return? What does x[x > 25] return?
20 40 and 30, 40, 50
Create a data frame called cities with three columns:
name: “Amsterdam”, “Rotterdam”, “The Hague”
population: 872680, 651406, 545838
province: “Noord-Holland”, “Zuid-Holland”, “Zuid-Holland”
cities <- data.frame(
name = c("Amsterdam", "Rotterdam", "The Hague"),
population = c(872680, 651406, 545838),
province = c("Noord-Holland", "Zuid-Holland", "Zuid-Holland")
)
cities <- data.frame(
name = c("Amsterdam", "Rotterdam", "The Hague"),
population = c(872680, 651406, 545838),
province = c("Noord-Holland", "Zuid-Holland", "Zuid-Holland")
)
How would u asses the population of rotterdam in three different ways?
cities$population[1]
cities[["population"]][1]
cities[,"population"][1]