Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
1K views
19 pages
R Lab Manual
Uploaded by
Pushpa Prashanth
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save R LAB MANUAL For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
1K views
19 pages
R Lab Manual
Uploaded by
Pushpa Prashanth
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save R LAB MANUAL For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save R LAB MANUAL For Later
You are on page 1
/ 19
Search
Fullscreen
Maharaja Education Trust © MIT First Grade College MEI: Department of Computer Applications g REVOLUTION Industrial Suburb, Manandavadi Road, Mysuru -570008, www.mitfgc.in Affiliated to University of Mysore, Accredited by NAAC with *A” Grade, ISO 9001-2015 Certified Institution VISION OF THE INSTITUTE Empower the individuals and society at large through educational excellence; se for a life dedicated to the service of fellow human beings and mother land. MISSION OF THE INSTITUTE To impact holistic education that enables the students to become socially responsive and useful, with roots firm on traditional and cultural values; and to hone their skills to accept challenges and respond to opportunities in a global scenario. Lecture Notes on: R PROGRAMMING LAB Course Code: BCADSC14-LAB Contact Hours: 04 hrs per week Formative Assessment Marks: 25 Summative Exam Marks: 25 Exam Duration: 03hrs Overview The following program problematic comprises of R programming basics and application of several Statistical Techniques using it, The module aims to provide exposure in terms of Statistical Analysis, Hypothesis Testing, Regression and Correlation using R. programming language. Learning Objectives The objective of this Laboratory to make students exercise the fundamentals of statistical analysis in environment. They would be able to analysis data for the purpose of exploration using Descriptive and Inferential Statistics. Students will understand Probability and Sampling Distributions and learn the creative application of Linear Regression in multivariate context for predictive purpose. Prepared by: Asst. Prof. Suhas B Raj Department: Computer Applications10. Course Outcomes: Install, Code and Use R Programming Language in R Studio IDE to perform basic tasks on Vectors, Matrices and Data frames. Explore fundamentals of statistical analysis in R environment. Describe key terminologies, concepts and techniques employed in Statistical Analysis. Define Calculate, Implement Probability and Probability Distributions to solve a wide variety of problems. Conduct and interpret a variety of Hypothesis Tests to aid Decision Making, Understand, Analyze, and Interpret Correlation Probability and Regression to analyze the underlying relationships between different variables List of Experiments Write a R program for different types of data structures in R. Write a R program that include variables, constants, data types Write a R program that include different operators, control structures, default values for arguments, returning complex objects. Write a R program for quick sort implementation, binary search tree. Write aR program for calculating cumulative sums, and products minima maxima and calculus. Write a R program for finding stationary distribution of markanov chains Write a R program that include linear algebra operations on vectors and matrices. Write a R program for any visual representation of an object with creating graphs usinggraphic functions: Plot (), Hist (), Linechart (), Pie (), Boxplot (), Scatterplots (). Write a R program for with any dataset containing data frame objects, indexing and sub setting data frames, and employ manipulating and analyzing data. Write a program to create an any application of Linear Regression in multivariate context forpredictive purpose.R PROGRAMMING LAB 1. WriteaR program for different types of datastructuresin R. Vector # Creating a character vector character_vector <- ¢ ("apple”, "banana", "cherry") character_vector output: [1] “apple” "banana" "cherry" Matrix # Creating a numeric matrix numeric_matrix <- matrix (1:6, nrow = 2, neol = 3) numeric_matrix output: (1) (2) 63) fj 135 2] 24 6 Lists # Creating a list my_list <- list (name = ¢("John","Daniel","Jack"), age = ¢ (30,53,40), hobbies =c ("reading”, "golf","Gaming")) my_list output: Sname:{1] "John", "Daniel" "Jack" Sage:[1] 30 53 40 Shobbies:{1] "reading" "golf". "Gaming" DataFrame # Creating a data frame data_frame <- data.frame (Name = c ("Alice”, "Bennett", "Charlie"),Age = ¢ (25, 30, 22), Gender =c ("Female”, "Male", "Male")) data_frame output: Name Age Gender 1 Alice 25 Female 2 Bennett 30 Male 3 Charlie 22 Male Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 1|17R PROGRAMMING LAB Factors # Creating a factor gender <- c ("Male","Female","Male","Female","Male") factor_gender <- factor (gender, levels = ¢ (""Male","Female")) factor_gender output: [1] Male Female Male Female Male Levels: Male Female Array #Creating an Array arr <- array (1:24, dim =e (4,3,2)) arr output: . 1 LU02) 63] 1s 9 12] 2 6 10 Bl 371 [4] 4 8 12 vod LUE) £3) Uj 1317 Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 2\17R PROGRAMMING LAB 2.Write a R program that include variables, constants, data types. # Define variables radius <-5 radius output-[1] 5 name <- "Alice" name output-[1] "Alice" age <-30L age output:{1] 30 is_student <- TRUE is_student output: [1] TRUE # Constants PI <3.14159265359 paste ("Constant Value:",PI) output:[1] "Constant Value 3.14159265359" GREETING < "Hello, World!" paste ("Constant Value:", GREETNG) output:[1] "Constant Value: Hello, World!" # Data pes print(class(radius)) output: [1] "numeric" print(class(name)) output: [1] "character" print(class(age)) output: [1] "integer" print(class(is_student)) output: [1] "logical" Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 3|17R PROGRAMMING LAB 3.Write a R program that include different operators, control structures, default values for arguments, returning complex objects # Arithmetic operators asl bed sum_result< ab sum_result output:[1] 15 diff result <- a-b diff result output:[1] 7 product_result <- a*b product_result output-{1] 44 division_result <-a/b division_result output:[1] 2.75 modulus_result
b) { print ("a is greater than b") else if (a
pivot] return(e(quick_sort(left), middle, quiet 4 veet = © (2,5,3,6,8,441,3,10) print ("Unsorted Vector") print(veet) output: [1] 253.684 1310 sorted_vector <- quick_sort(vect) print("sorted vector") print(sorted_vector) mena eeen Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 6/17R PROGRAMMING LAB # Define the structure for a Binary Search Tree node bst_node < fimetion(key) { return (list (key = key, left = NULL tight = NULL)) } # Function to insert a key into the BST insert <- function (root, key) { if (is.null(root)) { return(bst_node(key)) } if (key < root$key) { rootSleft < insert(rootSleft, key) } elseif (key > rootSkey) { rootSright < inse! , key) 5 return(root) 4 # Function to perform an in-order trave in_order_traversal <- function(root) { if (lis.mull(root)) in_order_traversal(rootSleft) cat(rootSkey, "") in_order_traversal(rootSright) r_traversal(bst) outputs] 23.589 Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 7/17R PROGRAMMING LAB 5.Write a R program for calculating cumul: maxima and calculus sums, and products minima # Sample vector of numbers numbers <- ¢ (1, 2, 3, 4, 5) # Calculate cumulative sum cumulative_sum < cumsum(numbers) cat ( mulative Sum:", cumulative_sum, "\n") output: Cumulative Sum: 1 3 6 10 15 # Calculate cumulative product cumulative_product <- cumprod(numbers) cat("Cumulative Product:", cumulative_product, "\n") output: Cumulative Product; 12 6 24 120 # Calculate minimum and maximum min_value <- min(numbers) ‘max_value
25):\n") subset_data<- data_frame{data_frame$Age > 25, ] print(subset_data) output: Name Age Gender Score 2 Bennett30 Male 92 4 David 28 Male 88 5 Emma 35 Female 95 # Calculate Summary Statistics summary_stats <- summary(data_frame$Score) summary_stats output: Min. Ist Qu. Median Mean 3rd Qu. Max. 78.0 85.0 88.0 87.6 92.0 95.0 # Add a new column data_frame$Grade < ifelse(data_frame$Score >= 90, "A’ print(data_frame) ifelse(data_frame$Score output: Name Age Gender Score Grade 1 Alice 25 Female 85 B 2 Bennete 30 Male 92 A 3 Charlie 22 Male 78 € 4 David 28 Male 88 B 5 Emma 35 Female 95 9 A Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 1417R PROGRAMMING LAB # Grouping and Aggregation gender_avg_score <- aggregate (data_frame$Score, by = list(data_frameSGender), FUN =mean) colnames(gender_avg_score) <- ¢("Gender", "Avg_Score") print(gender_avg_score) output: Gender Avg_Score 1 Female 90 2 Male 86 SX Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 1S|17R PROGRAMMING LAB 10.Write a program to create an any application of Linear Regression in multivariate context for predictive purpose. #Load the mtcars dataset data(mtcars) # Explore the dataset head(mtcars) output: Fa mpg cyl disp hp drat wt qsec vs am gear carb zda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 160 110 3.90 2.875 17.02 108 93 3.85 2.320 18.61 258 110 3,08 3,215 19.44 360 175 3.15 3.440 17.02 zda RX4 Wag 21.0 Datsun 710 22.8 Hornet 4 Drive 21.4 Hornet Sportabout 18.7 otro core wo ee Ree ee # Fit a multivariate linear regression m +# We'll predict ‘mpg’ (miles per gallon) ‘model < Im(mpg ~ hp + wt, data = model ‘hp’ (horsepower) and 'wt" (weight) call: Am(formula = mpg ~ hp + wt, data = mtcars) Coefficients: | (Intercept) ap we 37.22727 -0.03177 3.87783 Im(formula hy ars) call: Am(formula = mpg ~ hp + wt, data = mtcars) Coefficients: (Intercept) np we 37,22727 --0,03177 «= -3.87783 Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 16|17R PROGRAMMING LAB # Print the model summary summary(model) Call: Am(formula = mpg ~ hp + wt, data = mtcars) Error t value Pr(>It|) 59879 23.285 < 2e-16 00903 -3.519 0.00148 Residua: Min 10 Median 30 Max -3.941 -1.600 -0.182 1.050 5.854 Coefficients: Estimate Std. (Intercept) 37.22727 1. hp -0.03177 0. we 3.877830. Signif. codes: 0 + 1 0. 63273 -€.129 1.12e-06 002 *#*" 0,02 *#" 0.05 4 OL SAD Residual standard error: 2.593 on 29 degrees of freedom Multiple R-squared: 0.8268, Adjusted R-squared: 0.8148 Festatistic: 69.21 on 2 and 29 DF, p-value: 9.109e-12 #Make predictions using the model new data < data. frame(hp = ¢(150, 200) 3.5, 4.0) predictions <- predict(model, newdata = new_data) cat("Predicted MPG for new data:\n") print(predictions) output: Predicted Suhas B Raj, Asst Prof. Dept of CA, MIT FGC, Mysore Page 17|17
You might also like
DS Sanchit Sir Notes
PDF
No ratings yet
DS Sanchit Sir Notes
131 pages
ADA Notes-NEP 2023-1
PDF
No ratings yet
ADA Notes-NEP 2023-1
17 pages
AJS - NJS Manual - 1
PDF
No ratings yet
AJS - NJS Manual - 1
45 pages
Daa Lecture Notes
PDF
No ratings yet
Daa Lecture Notes
120 pages
Daa Lab Manual
PDF
No ratings yet
Daa Lab Manual
60 pages
PHP Practicals
PDF
No ratings yet
PHP Practicals
36 pages
Module-3 Syntax Analyzer
PDF
No ratings yet
Module-3 Syntax Analyzer
80 pages
BCA 3rd Data Structure 1 20
PDF
100% (1)
BCA 3rd Data Structure 1 20
20 pages
Web App Lab Manual R20 by Hemanth
PDF
80% (5)
Web App Lab Manual R20 by Hemanth
41 pages
DAA PPT - Unit - I
PDF
No ratings yet
DAA PPT - Unit - I
111 pages
AI - Model Paper Answers - 240817 - 173447
PDF
No ratings yet
AI - Model Paper Answers - 240817 - 173447
27 pages
BCS306B Manual
PDF
No ratings yet
BCS306B Manual
27 pages
R22 - OOPS Using JAVA Lab Manual 2-2
PDF
No ratings yet
R22 - OOPS Using JAVA Lab Manual 2-2
58 pages
WD File
PDF
100% (2)
WD File
22 pages
ST Unit-3-1
PDF
No ratings yet
ST Unit-3-1
8 pages
IT3401 Web Essential Lab
PDF
No ratings yet
IT3401 Web Essential Lab
51 pages
Data Structure Using C and C++ Basic
PDF
100% (1)
Data Structure Using C and C++ Basic
8 pages
Chapter - 2: Fundamentals of Algorithmic Problem Solving
PDF
No ratings yet
Chapter - 2: Fundamentals of Algorithmic Problem Solving
23 pages
Introduction To The Design and Analysis of Algorithms - Lecture Notes, Study Material and Important Questions, Answers
PDF
No ratings yet
Introduction To The Design and Analysis of Algorithms - Lecture Notes, Study Material and Important Questions, Answers
16 pages
Statistical Lab Using R-Programming Lab Manual and Workbook: Department of Mathematics
PDF
No ratings yet
Statistical Lab Using R-Programming Lab Manual and Workbook: Department of Mathematics
58 pages
EMERGENCY
PDF
No ratings yet
EMERGENCY
19 pages
Glocal University: Practical File of R Programming
PDF
100% (1)
Glocal University: Practical File of R Programming
32 pages
Java Lab Manual
PDF
No ratings yet
Java Lab Manual
26 pages
CS3361 - Data Science Laboratory
PDF
No ratings yet
CS3361 - Data Science Laboratory
31 pages
R Programming Lab
PDF
No ratings yet
R Programming Lab
14 pages
BCA-SEP-lesson Plan - R-Programming
PDF
No ratings yet
BCA-SEP-lesson Plan - R-Programming
5 pages
OOP Java - IMP M 1
PDF
No ratings yet
OOP Java - IMP M 1
14 pages
JDBC Api Components and Drivers
PDF
100% (1)
JDBC Api Components and Drivers
15 pages
pst1 1st Sem Bca
PDF
No ratings yet
pst1 1st Sem Bca
14 pages
Mini Project Report: Visual Applications of Sorting Algorithms
PDF
100% (2)
Mini Project Report: Visual Applications of Sorting Algorithms
25 pages
System Programming & Operating System: A Laboratory Manual FOR
PDF
No ratings yet
System Programming & Operating System: A Laboratory Manual FOR
45 pages
CS-605 Data - Analytics - Lab Complete Manual (2) - 1672730238
PDF
No ratings yet
CS-605 Data - Analytics - Lab Complete Manual (2) - 1672730238
56 pages
Ant Ma8551 U1
PDF
No ratings yet
Ant Ma8551 U1
73 pages
HN DAA 15CS43 LectureNotes 1
PDF
20% (5)
HN DAA 15CS43 LectureNotes 1
28 pages
DSAL Lab Manual
PDF
No ratings yet
DSAL Lab Manual
61 pages
DAA All 5 Units Notes
PDF
No ratings yet
DAA All 5 Units Notes
87 pages
18csl47 - Daa Lab Manual
PDF
No ratings yet
18csl47 - Daa Lab Manual
36 pages
Horspool Algorithm
PDF
No ratings yet
Horspool Algorithm
6 pages
ADA - Question - Bank
PDF
No ratings yet
ADA - Question - Bank
6 pages
Experiment-1 Aim: Write A Program For Implementation of Bit Stuffing
PDF
No ratings yet
Experiment-1 Aim: Write A Program For Implementation of Bit Stuffing
56 pages
Lecture 33 Algebraic Computation and FFTs
PDF
No ratings yet
Lecture 33 Algebraic Computation and FFTs
16 pages
DAUR Lab Manual
PDF
No ratings yet
DAUR Lab Manual
14 pages
Program-1 Write A Program in C To Create Two Sets and Perform The Union Operation On Sets
PDF
No ratings yet
Program-1 Write A Program in C To Create Two Sets and Perform The Union Operation On Sets
22 pages
What Are The Phases of Compiler Design
PDF
No ratings yet
What Are The Phases of Compiler Design
6 pages
5 Sem Lab Manual R Programming BCA-BSC
PDF
No ratings yet
5 Sem Lab Manual R Programming BCA-BSC
16 pages
Format - Summer Internship Report
PDF
No ratings yet
Format - Summer Internship Report
6 pages
Unit 4-Decrease and Conquer & Divide and Conquer
PDF
No ratings yet
Unit 4-Decrease and Conquer & Divide and Conquer
13 pages
Co Po Mapping Justification DSA
PDF
No ratings yet
Co Po Mapping Justification DSA
3 pages
Ada Lab Manual
PDF
No ratings yet
Ada Lab Manual
57 pages
CBNST Lab File
PDF
0% (1)
CBNST Lab File
20 pages
Recursively Enumerable Languages
PDF
No ratings yet
Recursively Enumerable Languages
8 pages
Ai Viva Question
PDF
No ratings yet
Ai Viva Question
4 pages
DAA Question Bank
PDF
No ratings yet
DAA Question Bank
3 pages
BCA Data Structures Notes
PDF
No ratings yet
BCA Data Structures Notes
24 pages
Challenges InThreading A Loop - Doc1
PDF
100% (2)
Challenges InThreading A Loop - Doc1
6 pages
Cs6402 DAA Notes (Unit-3)
PDF
No ratings yet
Cs6402 DAA Notes (Unit-3)
25 pages
Mathematics of Cryptography: Part I: Modular Arithmetic, Congruence, and Matrices
PDF
No ratings yet
Mathematics of Cryptography: Part I: Modular Arithmetic, Congruence, and Matrices
82 pages
Unit 1: Database Management System (DBMS) Historical Perspective
PDF
100% (1)
Unit 1: Database Management System (DBMS) Historical Perspective
30 pages
Algorithms Design and Analysis by Udit Agarwal PDF
PDF
67% (15)
Algorithms Design and Analysis by Udit Agarwal PDF
245 pages
DAA Question Bank
PDF
No ratings yet
DAA Question Bank
39 pages