R Basics - Day 1 Flashcards
What is R?
A programming language used for statistical analysis, data manipulation, and visualization.
What is RStudio?
An Integrated Development Environment (IDE) for writing, running, and debugging R code.
How do you assign a value to a variable in R?
Using the ‹- operator.
(e.g., x ‹- 10)
What is a vector in R?
A sequence of elements of the same type.
[e.g., c (1, 2, 3) ]
How do you create a vector in R?
Use the c () function.
example: numbers <- c(10, 20, 30)
What function calculates the mean of a vector?
mean ()
example: mean (numbers)
How do you access an element in a vector?
Use square brackets.
example: numbers[1] gives the first element
How do you calculate the sum of a vector?
Use the sum () function.
example: sum (numbers)
What is a data frame in R?
A table-like structure with rows and columns, where each column can be a different data type.
How do you create a data frame in R?
Use the data. frame() function.
example:
names <- c(“Alice”, “Bob”)
scores <- c(85, 90)
df <- data.frame(Name = names, Score = scores)
How do you view the first rows of a data frame?
Use the head () function.
example: head (df)
What does the print () function do in R?
Outputs the value of a variable or expression to the console.
What does the class () function do in R?
Returns the data type of a variable.
example: class (numbers)
What does the length () function do?
Returns the number of elements in a vector.
example: length (numbers)
What is the purpose of the help () function?
Displays documentation for a function. example: help (mean)