- help(function) # Show documentation for a function
- ?function # Shortcut for
help
- help.search("topic") # Search for functions on a topic
- getwd() # Show the current working directory
- setwd("path") # Change working directory
- ls() # Show objects in the workspace
- rm(object) # Remove an object
- rm(list = ls()) # Clear the workspace
- install.packages("package") # Install a package
- library(package) # Load a package
- update.packages() # Update all installed packages
- c(1, 2, 3) # Create a vector
- seq(1, 10, by = 2) # Create a sequence
- rep(1, times = 5) # Repeat elements
- length(vector) # Length of a vector
- matrix(1:6, nrow = 2, ncol = 3) # Create a matrix
- t(matrix) # Transpose a matrix
- list(a = 1, b = 2) # Create a list
- data.frame(a = 1:3, b = c("X", "Y", "Z")) # Create a data frame
- head(df) # Show the first few rows of a data frame
- tail(df) # Show the last few rows
- str(df) # Structure of a data frame
- summary(df) # Summary of a data frame
- factor(c("A", "B", "A")) # Create a factor
- levels(factor) # Show levels of a factor
- vector[2] # Access the second element of a vector
- matrix[1, 2] # Access the element at row 1, column 2
- dataframe$column # Access a column in a data frame
- subset(df, column > 10) # Filter rows based on a condition
- sort(vector) # Sort a vector
- order(df$column) # Get sorted indices based on a column
- merge(df1, df2, by = "column") # Merge two data frames by a common column
- mean(vector) # Calculate the mean
- median(vector) # Calculate the median
- sd(vector) # Calculate the standard deviation
- sum(vector) # Sum of the elements
- table(vector) # Create a frequency table
- runif(10, min = 0, max = 1) # Generate random numbers from a uniform distribution
- rnorm(10, mean = 0, sd = 1) # Generate random numbers from a normal distribution
- plot(x, y) # Create a scatter plot
- hist(vector) # Create a histogram
- boxplot(vector) # Create a box plot
- plot(x, y, main = "Title", xlab = "X-Axis", ylab = "Y-Axis")
- barplot(vector, col = "blue") # Create a bar plot with color
- for (i in 1:10) { print(i) } # For loop
- while (condition) { ... } # While loop
- my_function <- function(x) { return(x^2) } # Create a function
- my_function(2) # Call the function