Write a R program to create a sequence of numbers from 20 to 50 and find the mean of numbers from 20 to 60 and sum of numbers from 51 to 91

1. Introduction

This R program creates a sequence of numbers from 20 to 50 and then computes the mean of numbers from 20 to 60 as well as the sum of numbers from 51 to 91.

2. Program Steps

1. Create a sequence of numbers from 20 to 50.

2. Calculate the mean of numbers from 20 to 60.

3. Calculate the sum of numbers from 51 to 91.

4. Display the results.

3. Code Program

# Create a sequence of numbers from 20 to 50
sequence_20_50 <- 20:50

# Calculate the mean of numbers from 20 to 60
mean_20_60 <- mean(20:60)

# Calculate the sum of numbers from 51 to 91
sum_51_91 <- sum(51:91)

# Display the results
cat("Mean of numbers from 20 to 60: ", mean_20_60, "\n")
cat("Sum of numbers from 51 to 91: ", sum_51_91, "\n")

Output:

Mean of numbers from 20 to 60: [Calculated Mean]
Sum of numbers from 51 to 91: [Calculated Sum]

Explanation:

1. 20:50: Creates a sequence of numbers from 20 to 50.

2. mean(20:60): Calculates the mean of numbers from 20 to 60.

3. sum(51:91): Calculates the sum of numbers from 51 to 91.

4. cat("Mean of numbers from 20 to 60: ", mean_20_60, "\n"): Displays the calculated mean.

5. cat("Sum of numbers from 51 to 91: ", sum_51_91, "\n"): Displays the calculated sum.


Comments