R Assignment
R Assignment
Assignment 2
1. Write a R program to create a sequence of numbers from 10 to 40 and find the mean of
numbers from 10 to 50 and sum of numbers from 41 to 81.
2. Write a R program to add two vectors of integers type and length 3.
3. Write a R program to sort a Vector in ascending and descending order.
4. The numbers below are the first ten days of rainfall amounts in 1996. Read them into a
vector using the c () function.
a)0.1 0.6 33.8 1.9 9.6 4.3 33.7 0.3 0.0 0.1
b) What was the mean rainfall, how about the standard deviation?
5. Write a R program to create a vector which contains 10 random integer values between -
50 and +50(use sample function to get random values)
6. Create a vector of the values of ex cos(x) at x = 3,3.1,3. 2,….6
7. Create the following vectors:
8. Use the function paste to create the following character vectors of length 30:
(a) ("label 1", "label 2", ...., "label 30").
Note that there is a single space between label and the number following.
(b) ("fn1", "fn2", ..., "fn30").
In this case, there is no space between fn and the number following.
9. Suppose
10. Write a R program to create a data frame using two given vectors and display the
duplicated elements and unique rows of the said data frame. (Use duplicated and unique
functions)
Given vectors are.
a = c (10,20,10,10,40,50,20,30)
b = c(10,30,10,20,0,50,30,30)
13. Write a R program to check whether a given number is a palindrome number or not.
14. A railway employee is paid 1200/- (rupees) per day for regular 8 hours of work. Any
hours over that are paid overtime rate of 100/- per hour. From the employee’s gross pay
(total pay per month) 2% is deducted for professional tax, 10% is deducted for provident
fund and 5% deducted for income tax. However, the employee will also get 2% (of the
gross pay) for the education of a child. Write a R program that will read the number of
extra hours (which the employee worked during a month of 30 days) and the number of
children the employee has. The program will output the employee’s gross pay (total pay
earned by the employee by working). The program also outputs the net take-home pay
with earning for child education and after deductions for a month of 30 days.
15. Given an array of integers. Find a peak element in it. An array element is peak if it is
NOT smaller than its neighbours. For corner elements, we need to consider only one
neighbour. For example, for input array {5, 10, 20, 15}, 20 is the only peak element. For
input array {10, 20, 15, 2, 23, 90, 67}, there are two peak elements: 20 and 90. Write a R
program to print all the peak elements in a given array.