 1. Print in R
r
Copy
Edit
print("Hello Boss!")
🔹 2. Comments in R
r
Copy
Edit
# This is a single-line comment
🔹 3. Variables in R
r
Copy
Edit
x <- 10
y <- "Data"
🔹 4. Concatenate Elements
r
Copy
Edit
v <- c(1, 2, 3, 4)
print(v)
🔹 5. Multiple Variables
r
Copy
Edit
a <- 5
b <- 10
c <- a + b
print(c)
🔹 6. Variable Names
r
Copy
Edit
user_name <- "Boss"
user_age <- 25
🔹 7. Data Types
r
Copy
Edit
num <- 10.5        # Numeric
str <- "Hello"     # Character
bool <- TRUE       # Logical
vec <- c(1, 2, 3)  # Vector
🔹 8. Strings
r
Copy
Edit
name <- "R Programming"
paste("Welcome to", name)
🔹 9. Boolean
r
Copy
Edit
is_true <- TRUE
is_false <- FALSE
🔹 10. Operators
r
Copy
Edit
a <- 10
b <- 3
a + b   # Addition
a > b   # Comparison
a == b  # Equal
a %% b  # Modulus
🔹 11. If Else
r
Copy
Edit
x <- 10
if (x > 5) {
  print("Greater than 5")
} else {
  print("5 or less")
}
🔹 12. List
r
Copy
Edit
my_list <- list(name="Boss", age=25, scores=c(90, 85))
print(my_list)
🔹 13. Matrices
r
Copy
Edit
matrix_data <- matrix(1:6, nrow=2, ncol=3)
print(matrix_data)
🔹 14. Data Frames
r
Copy
Edit
df <- data.frame(Name=c("A", "B"), Age=c(20, 25))
print(df)
🔹 15. Functions
r
Copy
Edit
add_numbers <- function(x, y) {
  return(x + y)
}
🔹 16. Call a Function
r
Copy
Edit
result <- add_numbers(5, 3)
print(result)
🔹 17. Global Variable
r
Copy
Edit
x <- 5
my_func <- function() {
  x <<- 10  # Modify global x
}
my_func()
print(x)
🔹 18. Vectors
r
Copy
Edit
my_vector <- c(1, 2, 3, 4, 5)
print(my_vector)