Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

R Exercises:


Certainly! Here are some simple R language exercises along with explanations:

  1. Create a Vector: Create a vector containing the numbers from 1 to 10.

  2. Example

    numbers <- 1:10

  3. Calculate the Mean: Calculate the mean (average) of the numbers from the vector created above.

  4. Example

    mean_value <- mean(numbers)

  5. Find the Maximum: Find the maximum value from the vector.

  6. Example

    max_value <- max(numbers)

  7. Generate Random Numbers: Generate a vector of 5 random numbers between 1 and 100.

  8. Example

    random_numbers <- sample(1:100, 5)

  9. Calculate the Median: Calculate the median of the random numbers generated.

  10. Example

    median_value <- median(random_numbers)

  11. Create a Matrix: Create a 3x3 matrix with numbers from 1 to 9.

  12. Example

    matrix_data <- matrix(1:9, nrow = 3)

  13. Transpose a Matrix: Transpose the matrix created above.

  14. Example

    transposed_matrix <- t(matrix_data)

  15. Subset Data: Create a subset of the random numbers vector containing values greater than 50.

  16. Example

    subset_numbers <- random_numbers[random_numbers > 50]

  17. Count Values: Count the occurrences of each value in the random numbers vector.

  18. 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.


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java