Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Q1.

a) Take any two numbers of your choice.


b) assign these numbers to two variables and add them.
c) assign the sum to a variable “answer1”
d) Now subtract one number from the other and assign the result to a variable “
answer 2”
e) Now get the product of answer1 and answer2 and assign the product to a variable
“Final_answer”
f) Verify your answer by computing P2−Q2

Q2.

a) Perform the following:3+4*(5^2-9) and assign the result to a new variable and
display its value
b) Assign 4 to x and 7 to y. Test x and y for the following operators: ==, !=, >, >=,
<=
c) Check the conditions 2>3 and 3<4 by using the operators & and |
d) Enter a comment line “ All exercise completed” in a R-script
e) Save your script

Q3.

a) Create a variable as integer, double, character and logical


b) Check their type by class() and typeof() function
c) Convert integer to numeric
d) Convert logical to integer
e) Convert integer to logical

Q4.

a) Create a vector with the even numbers less than 10.


b) Use name function to name the vector
c) Check the data type of the vector using class and typeof function
d) Now change it to a vector of integers
e) Find the number of elements in this vector.
f) Access 3rd and 5th elements of this vector

Q5.

a) Create a vector with the names of your family members.


b) Find the length of the vector
c) Check the data type of the vector using class and typeof function

Q6. Create two vectors of same length. Apply all arithmetic operations on this two and display the
result in each case

Q7.

a) Create a list with the First name of four members of your family, their age,
Surname. Use Surname “Gupta” for all members
b) Check the data type using str()
c) Access the name and age from the list
d) Change the surname to “Sharma”

Q8.

a) Create two matrices of same size


b) Find the sum , difference
c) The operation %*% can be used to multiply two matrices

Q9.

Write a code to Solve:

x + 2y = 4

x-y=1

Q10. Create an array that consists of 3 matrices of size 1X2 with the elements as”RED” and “BLUE”

Q11.

a) Create a data frame with three variables and two observations


b) Check the structure and data type of Data Frame
c) Use dataframename$variablename to access a specific variable/object in a data
frame

Q12.

a) create a data frame with the 5 observations consisting of variables : Name, Age,
Educational qualification, year of experience, monthly salary earned.
b) Display top 5 observations
c) Display bottom 5 observations
d) Use display data with a condition
e) Now add a row to the data frame
f) Add a column to the data frame by specifying its name as “Revised_Salary” and
compute the Revised Salary with a 40% hike
g) Relocate the column after monthly salary earned

Q13.

a) Assign your name to a variable.


b) Find out the number of characters within it
c) Change it to uppercase and lower case
d) Extract your surname from the name using R-command

Q14.

a) Assign your date of birth to a variable


b) Save it as date
c) Assign today’s date to another variable and calculate your age in days.

Q15. A patient is taking the first dose of a medicine on 15 th May 2023. He has to take this medicine
on the 15th day of every moth for next 6 months. Help the patient by displaying all the dates he has
to take medicine.
Q16. Write the command for displaying the present system’s time and format it as HH:MM:SS

Q17.

a) Take an integer and check if it is even. Print” the number is even” if it is even.
b) Take an integer and check if it is even. Print” the number is even” if the condition
is satisfied or “the number is odd” if not satisfied.
c) Enter a number and check it is a two-digit number and print your result statement
d) Enter a string and check if a particular word belongs to that string.
e) Access the present system time, and print a “Good Morning”/”Good afternoon” or
“Good Evening” message accordingly

Q18. Use for loop for the following questions

a) Find the sum and average of first 10 natural numbers using for loop
b) Find the sum of first 10 odd numbers
c) Find the sum of the squares of first
d) 10 natural numbers.
e) Print the following pattern:
*

**

***

****

*****

Q19. A man has Rs. 15000 in his account. He is spending Rs. 2875 on a recurrent basis from his
account. A minimum balance of Rs. 5000 must be maintained in the account to keep it active.
Assuming that there is no amount credited to his account during this period, write a code in R to
determine how many transactions he will be able to make and what how much would be remaining
in his account after the last transaction, also print the balance after every transaction and display a
message “Amount not sufficient” when the balance is less than minimum .

Q20.

a) Write a function to compute the area of a circle.

b) Write a function to compute the total amount of a person, taking the principal and
rate of interest as user input

c) Write a function to compute profit where the quantity purchased, cost of each item
and the selling price of each item is given by the user.

d) Write a function that points the grade of the students according to the obtained
marks:
Less than 40: Fail
Greater than or equal to 40 but less than 60: C
Greater than or equal to 60 but less than 80:B
Greater than or equal to 80 : A

e) Write a script that points the grade of a group of students according to the obtained
marks:
Less than 40: Fail
Greater than or equal to 40 but less than 60: C
Greater than or equal to 60 but less than 80:B
Greater than or equal to 80 : A

f) Create a function that finds out the greatest number among the three given numbers

g) Write a function to check if a number is a factor of 12

h) Write a function to take two numbers from the user and check if the first one is a
factor of the second one.

You might also like