0% found this document useful (0 votes)
10 views3 pages

R Questions

The document provides a comprehensive guide on performing various operations in R, including arithmetic calculations, vector manipulations, matrix operations, and data frame handling. It also covers loops, conditional statements, data import from Excel, and data visualization techniques such as histograms, boxplots, line plots, scatter plots, and bar charts. Each section includes specific tasks and examples to illustrate the functionality of R programming.

Uploaded by

daveaditi26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

R Questions

The document provides a comprehensive guide on performing various operations in R, including arithmetic calculations, vector manipulations, matrix operations, and data frame handling. It also covers loops, conditional statements, data import from Excel, and data visualization techniques such as histograms, boxplots, line plots, scatter plots, and bar charts. Each section includes specific tasks and examples to illustrate the functionality of R programming.

Uploaded by

daveaditi26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Essentials of the R Language (File R1 - Calculation)

1. Perform the following arithmetic operations in R:


o Add 10 and 17
o Multiply 10 by 15
o Divide 140 by 7
o Subtract 6 from 100
o Calculate 2 to the power of 5
2. Write an R script to create a sequence of numbers:
o From 1 to 100, with an interval of 5
o From 1 to 100, with an interval of 3
3. Create a variable x with a value of -100, and perform the following operations:
o Add 70 to x
o Find the absolute value of x
4. Define two variables u = 19 and v = 11, and:
o Find their sum
o Use the sum() function to add them
5. Write an R script to calculate the area of a circle where the radius is 5.

Vectors (File R2 - Vectors)

6. Create a numeric vector y with the values (10, 12, -32, 40, 50, 100), then:
o Multiply all elements by 3
o Find the absolute values of the vector
o Check the class of the vector
o Find the length, mean, maximum, and minimum of the vector
7. Create a vector z that repeats the values (1, 2, 3, 4, 5) three times.
8. Extract the 3rd and 4th elements from the vector y.

Matrices (File R3 - Matrices)

9. Create a 3x3 matrix using the values (1, 4, 7, 2, 5, 8, 3, 6, 9) and display its:
o Class
o Attributes
10. Define a matrix D with values (10, 40, 70, 20, 50, 80, 30, 60, 90) and perform the
following operations:
o Multiply all elements of D by 2 and subtract 5
o Create another matrix E and find D + E, D - E, and D * E (matrix
multiplication)

Arrays and Lists (File R4 - Arrays and Lists)

11. Create a 2D array with dimensions (2, 3, 4) and fill it with numbers from 1 to 24.
12. Create a list with the following information:
o Name: "Arun Julka"
o Age: 53
o City: "New Delhi"
o Hobbies: "reading", "coding", "painting"
Loops (File R5 - Loops)

13. Write a for loop in R that prints numbers from 1 to 5.


14. Write a while loop that starts from 6 and prints numbers up to 10.
15. Use a repeat loop to print numbers from 11 to 15 and stop the loop using break.

Factors and Data Frames (File R6 - Factors and Data Frames)

16. Create a factor from the data: ("Male", "Female", "Male", "Child", "Child",
"Male", "Female", "Female").
17. Create a data frame using the following details:
o Name: "Arun Julka", "Arvinder", "Deepak Mehra", "Sanjay Garg",
"Soma Jain"
o Age: 60, 55, 52, 56, 45
o Gender: "M", "F", "M", "M", "F"
18. Extract the first row and the third row from the data frame.
19. Extract the name column from the data frame.

Conditional and Control Flows (File R7 - Conditional Statements)

20. Write an if statement to check if a variable x = 10 is greater than 5.


21. Write an if-else statement to check whether y = 15 is greater than 15 or not.
22. Implement a for loop that prints numbers from 1 to 10 but stops when it reaches 5.
23. Implement a for loop that prints only odd numbers from 1 to 10 using the next
statement.

Importing Data from Excel (File R8 - Importing from Excel)

24. Import an Excel file named "CreditLimit.xlsx" into R and:


o Display the first 6 rows of the dataset
o Display the last 6 rows of the dataset
o Show a summary of the dataset
25. Extract and summarize the Income column from the CreditLimit dataset.

Data Visualization in R

Histograms (File R11 - Histograms)

26. Create a histogram for the Sepal.Length column in the iris dataset.
27. Create a histogram for the Petal.Length column with:
o Title: "Histogram"
o X-axis label: "Length"
o Y-axis label: "Frequency"
o Color: Red

Boxplot (File R12 - Boxplot)

28. Create a boxplot for the Sepal.Length column in the iris dataset.
29. Create a boxplot for Petal.Length with:
o Title: "Petal Length"
o X-axis label: "Species"
o Y-axis label: "Petal Length"
o Box color: Pink
o Border color: Red

Line Plot (File R13 - Line Plot)

30. Create a line plot for the vector (7, 12, 28, 3, 41).
31. Modify the above plot to:
o Use both points and lines (type = "o")
o Change the color to green
o Add a title "Line Plot"
o Label the x-axis as "points" and the y-axis as "Frequency"

Scatter Plot (File R14 - Scatter Plot)

32. Create a scatter plot for Sepal.Length and Sepal.Width in the iris dataset.
33. Modify the scatter plot to:
o Use red dots
o Title: "Scatter Plot"
o X-axis label: "sepal_length"
o Y-axis label: "sepal_width"

Bar Chart (File R15 - Bar Chart)

34. Count the number of observations for each species in the iris dataset and create a bar
chart with:
o Title: "Distribution of Iris Species"
o X-axis label: "Species"
o Y-axis label: "Count"
o Colors: Blue, Green, Pink

You might also like