Sure, getting started with R is pretty straightforward. Here's a simple guide with examples:
Once installed, open R or RStudio on your computer.
Let's start with some simple arithmetic operations:
Example
# Addition
3 + 5
# Subtraction
10 - 2
# Multiplication
4 * 6
# Division
20 / 5
You can store values in variables:
Example
# Assigning values to variables
x <- 10
y <- 5
# Using variables in operations
z <- x + y
z
Vectors are sequences of elements. Here's how you can create and work with vectors:
Example
# Creating a numeric vector
numbers <- c(1, 2, 3, 4, 5)
# Creating a character vector
fruits <- c("apple", "banana", "orange")
# Accessing elements of a vector
numbers[3] # This will print the third element of the vector "numbers"
R comes with many built-in functions:
Example
# Square root function
sqrt(25)
# Mean function
mean(c(1, 2, 3, 4, 5))
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
This is just the beginning! As you become more comfortable with these basics, you can explore more advanced topics like data visualization, statistical analysis, and machine learning. There are plenty of online tutorials, courses, and resources available to help you learn and master R.