Absolutely! Here's a beginner-friendly introduction to R with examples:
R is a programming language and environment for statistical computing and graphics. It's widely used by statisticians, data analysts, and researchers to analyze data and create visualizations.
Example
# Addition
3 + 5
# Subtraction
10 - 2
# Multiplication
4 * 6
# Division
20 / 5
In R, you can store values in variables.
Example
# Assigning values to variables
x <- 10
y <- 5
# Using variables in operations
z <- x + y
z # This will print the value of z, which is 15
Vectors are sequences of elements of the same data type.
Example
# Creating a numeric vector
numbers <- c(1, 2, 3, 4, 5)
# Creating a character vector
fruits <- c("apple", "banana", "orange")
R comes with many built-in functions.
Example
# Square root function
sqrt(25) # This will return the square root of 25, which is 5
# Mean function
mean(c(1, 2, 3, 4, 5)) # This will return the mean of the vector, which is 3
Data frames are used to store tabular data.
Example
# Creating a data frame
df <- data.frame(
Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 35),
Sex = c("Female", "Male", "Male")
)
# Viewing the data frame
df
These examples cover some basic concepts in R to get you started. As you continue learning, you can explore more advanced topics such as data manipulation, plotting, statistical analysis, and machine learning. R has a vast community and plenty of resources available online for further learning.