






























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
R programming lab sample source code
Typology: Schemes and Mind Maps
1 / 38
This page cannot be seen from the preview
Don't miss anything!
_______________________ in “NME: Data Science and Big data AnalyticsLab”(20UCA4NM2) for the IV Semester during the Academic year
1. Adding two matrixes using array Aim To Perform a R Program on adding two matrixes using array Algorithm Step1: Start the Process Step2: Initialize two matrixes, and assign values in two different variables. Step3: print the addition of two matrixes as a result. Step 4: As in the same way of addition, we can subtract, multiply, and division process can be carried out. Step 5: print the result of subtracted, multiplied and divided values of two matrix. Step 6: Stop the process
R Program
Aim To Perform a R Program on arithmetic operations as a simple calculator. Algorithm Step1: Start the Process Step2: Initialize add, subtract, multiply and division function to perform the addition, subtraction, multiplication and division operations Step3: Getting a input of two numbers for the arithmetic operation as a integer value. Step4: Execute the program to perform the arithmetic operation and we can get the output. Step5: Stop the process
Aim To Perform a R Program on print the Multiplication table from the given number. Algorithm Step1: Start the Process Step2: Initialize the variable, for print the multiplication table. Step3: To print the multiplication table, we can use the for-loop statement. Step4: Using with the for-loop statement increment the variable value. Step5: Print the given value and also print the given number multiplication table. Step6. Stop the Process.
num = as.integer(readline(prompt = "Enter a number: "))
for(i in 1:10) { print(paste(num,'x', i, '=', num*i)) }
Enter a number: 7 [1] "7 x 1 = 7" [1] "7 x 2 = 14" [1] "7 x 3 = 21" [1] "7 x 4 = 28" [1] "7 x 5 = 35" [1] "7 x 6 = 42" [1] "7 x 7 = 49" [1] "7 x 8 = 56" [1] "7 x 9 = 63" [1] "7 x 10 = 70" Result Thus, the program was successfully verified and Executed
Result Thus, the program was successfully verified and Executed
5. To Convert Decimal into Binary using Recursive Aim To Perform a R Program on Decimal into Binary using Recursive Algorithm STEP 1: Call function convert_to_binary() STEP 2: Pass the decimal number which needs to be converted to binary as decnum to the function. STEP 3: inside the function check if the given number is greater than 1, if yes call function convert_to_binary() again with decnum/2 as the argument STEP 4: divide the number decnum successively by 2 and print the remainder
Aim To Perform a R Program on K-means clustering technique. Algorithm Step 1: Installing the relevant packages and calling their libraries Step 2: Loading and making sense of the dataset. Step 3: Eliminating the target variable Step 4: The elbow point technique Step 5: Implementing K-means Step 6: Plotting our data-points in clusters Step 7: Kmeans with K = 3 Step 8: Plotting the new clustered graph
R Program
install.packages("ClusterR") install.packages("cluster")
library(ClusterR) library(cluster)
iris_1 < - iris[, - 5 ]
set.seed( 240 ) # Setting seed kmeans.re < - kmeans(iris_1, centers = 3 , nstart = 20 ) kmeans.re
kmeans.re$cluster
cm < - table(iris$Species, kmeans.re$cluster) cm
plot(iris_1[c("Sepal.Length", "Sepal.Width")]) plot(iris_1[c("Sepal.Length", "Sepal.Width")], col = kmeans.re$cluster) plot(iris_1[c("Sepal.Length", "Sepal.Width")], col = kmeans.re$cluster, main = "K-means with 3 clusters")
kmeans.re$centers kmeans.re$centers[, c("Sepal.Length", "Sepal.Width")]
points(kmeans.re$centers[, c("Sepal.Length", "Sepal.Width")], col = 1 : 3 , pch = 8 , cex = 3 )
y_kmeans< - kmeans.re$cluster clusplot(iris_1[, c("Sepal.Length", "Sepal.Width")], y_kmeans, lines = 0 , shade = TRUE,
Result Thus, the program was successfully verified and Executed