Certainly! Here are some simple R language exercises along with explanations:
Create a Vector: Create a vector containing the numbers from 1 to 10.
Example
numbers <- 1:10
Calculate the Mean: Calculate the mean (average) of the numbers from the vector created above.
Example
mean_value <- mean(numbers)
Find the Maximum: Find the maximum value from the vector.
Example
max_value <- max(numbers)
Generate Random Numbers: Generate a vector of 5 random numbers between 1 and 100.
Example
random_numbers <- sample(1:100, 5)
Calculate the Median: Calculate the median of the random numbers generated.
Example
median_value <- median(random_numbers)
Create a Matrix: Create a 3x3 matrix with numbers from 1 to 9.
Example
matrix_data <- matrix(1:9, nrow = 3)
Transpose a Matrix: Transpose the matrix created above.
Example
transposed_matrix <- t(matrix_data)
Subset Data: Create a subset of the random numbers vector containing values greater than 50.
Example
subset_numbers <- random_numbers[random_numbers > 50]
Count Values: Count the occurrences of each value in the random numbers vector.
Example
value_counts <- table(random_numbers)
Plot Data: Plot a histogram of the random numbers vector.
Example
hist(random_numbers, main = "Histogram of Random Numbers", xlab = "Values", ylab = "Frequency")
These exercises cover basic operations such as creating vectors and matrices, calculating statistics, subsetting data, and plotting. They provide a good starting point for practicing R language fundamentals.