Practical File R by Komal
Practical File R by Komal
Of
R Programming
(24SEC0103P)
Step 1: Install R
Download R:
Install R:
Install RStudio:
• Features:
o You can save your code in files (.R, .Rmd) and execute them in parts.
o Syntax highlighting makes the code easier to read.
Output:
B. Create a vector of factor type for different weather conditions (Sunny, Rainy, Cloudy,
Snowy).
Program:
Output:
C. Create a list of vectors with the names of 5 countries and their respective populations.
Program:
Output:
D. Create a data frame with 5 employees, their age, department, and monthly salary.
Program:
Output:
Project 3 : Apply str () and summary () commands to the object
A. Str ():
• The str () function gives a compact, structural summary of an object.
• It shows the data type, structure, and a quick overview of the components of
the object, such as the variable names and their data types.
Program:
Output:
B. Summary ():
• The summary () function provides a statistical summary of an object.
Program:
Output:
Project 4 : String Manipulation
A. Load the stringr library and analyze the string: "apple, banana, cherry, date".Find and replace
"banana" with "blueberry".
Program:
Output:
Project 5: Vector Operations
A. Create a vector of numbers from 1 to 200, divisible by 4. Perform:
a) Calculate the length.
b) Extract the 10th, 25th, and 50th elements.
c) Replace values at index 15 with NA and find the mean of the modified vector.
Program:
Output:
Project 6:Matrix Operations
A. Create a 3x3 matrix with random integers:
a) Replace elements at positions (2, 2) with NA.
b) Compute the column-wise mean.
Program:
Output:
Project 7: String Operations
A. Analyze a vector of city names: c("New York", "London", "Tokyo", "Paris", "Berlin").
a) Count characters in each name.
b) Find cities containing the letter "o".
Program:
Output:
Project 8: Factor Data
A. Create a factor vector for vehicle types (Car, Bike, Bus, Train):
Program:
Output:
Project 9:Employee Data Management
A. Create a data frame of 10 employees with names, age, and monthly salaries. Find the
employee with the highest salary.
Program:
Output:
Project 10: Histogram Plotting
Program:
Output:
Project 11 : Scatter Plot with Regression
A. Create a scatter plot for height vs. weight data and add a regression line.
Program:
Output:
Project 12 : Data Frame Handling
A. Create a data frame of sales data (5 products, sales, profit). Find the most profitable
product.
Program:
Output:
Project 13 : Matrix Operations with Custom Data.
Program:
Output:
Project 14 : Advanced Visualization.
A. Plot the pressure dataset with different forms (line chart, bar chart).
Program:
Output:
Project 15. Generating a Matrix with Row-Major Order of Numbers in R.
A. Create a matrix m of five rows in a row -major order of numbers from 1 to 100
incremented by a step of 5 units.
a) Find row and columns -wise means of matrix m.
b) Find the minimum value for each row and column.
c) Find the transpose and sort the values in each columns in decreasing order.
d) Assign the row names as R1to R5 and column names C1 to C4.
e) Display all the elements of the second and fourth column without using indices.
f) Display all the elements of the first and third row without using indices.
g) Create a new matrix by deleting the second and fourth column of matrix m using indices and
column names.
h) Replace elements at indices (2,3), (2,4), (3,3), and (3,4) with NA values.
i) Replace elements at index (1,3) with NaN.
j) Check if matrix m contains any NA or NaN values and interpret the output.
k) Create two new matrices rm and cm by concatenating matrix m row-wise and column-wise with
itself.
Program:
Output:
Project 16. Matrix Multiplication with Randomly Generated Matrices in R.
Program:
Output: