0% found this document useful (0 votes)
5 views

algorithms

Uploaded by

sridharan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

algorithms

Uploaded by

sridharan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Exercise 1: Fahrenheit to Celsius

Aim

To write a R Program to convert the given temperature from


Fahrenheit to Celsius

Procedure

Step 1: Start the program

Step 2: Get the User Input

Step 3: Convert Input from Character to Numeric

Step 4: Convert Fahrenheit to Celsius

celsius <- (fahrenheit - 32) * (5/9)

Step 5: Display the Converted Temperature

Step 6: Stop the program

Exercise 2: Find the area of rectangle, square, circle and triangle


Aim

To write a R Program, to find the area of rectangle, square, circle


and triangle by accepting suitable input parameters from user.

Procedure

Step 1: Start the program

Step 2: Get the user input values

Step 3: calculate area of rectangle

area <- length * width

Step 4: Calculate area of square

area <- side^2

Step 5: Calculate area of triangle

area <- 0.5 * base * height

step 6: Print the results

Step 7: Stop the Program

Exercise 3: Find list of even numbers

Aim
To Write a R program to find list of even numbers from 1 to n using
R- Loops.

Procedure

Step 1: Start the program

Step 2: Read the user input N

Step 3: Set Up a Loop to Iterate Over a Sequence

Step 4 : Check if the Number is Even

if(i%%2==0)

Step 5: Print the Even Number

Step 6: Stop the Program

Exercise 4: Print squares of numbers in sequence.

Aim
To Create a function to print squares of numbers in sequence using
R Program

Procedure

Step 1: Start the program

Step 2: Get the user input N

Step 3: Define the Function

ps<-function(n)

Step 4: Set Up a Loop to Iterate Over a Sequence

Step 5: Call the Function : ps(n)

Step 6: Print the Square value

Step 7: Stop the Program

Exercise 5: Data frame using cbind() and rbind()

Aim

To Write a R program to join columns and rows in a data frame


using cbind() and rbind()
Procedure

Step 1: Start the program

Step 2: Create Data frame df1 and df2

Step 3: Combine Data Frames by Rows

df3<-rbind(df1,df2)
Step 4: Combine Data Frames by Columns

df3<-cbind(df1,df2)
Step 5: print the Data frame df3

Step 6: Stop the Program

Exercise 6: String Manipulation functions

Aim

To Implement different String Manipulation functions in R program

Procedure

Step 1: Start the program


Step 2: Define a Character String

x<-"welcome to svmc”

Step 3: Count the Number of Characters

count<-nchar(x)

Step 4: Convert String to Upper Case

up<-toupper(x)

Step 5: Split the String into Words

spl<-strsplit(x," " )

Step 6: Print the results

Step 7: Stop the Program

Exercise 7: Vectors, Lists, Data Frames

Aim

To Implement different data structures in R (Vectors, Lists, Data


Frames)

Procedure

Step 1: Start the program


Step 2: Define the X and Y Vectors

Step 3: Add the Two Vectors

z= X+Y
Step 4: Print the Resulting Vector

Step 5: Create a List

empList = list(empId, empName, numberOfEmp)


Step 5: Print the List value

Step 6: Create and Print data frame

df = data.frame(Name, Language, Age)


Step 7: Stop the Program

Exercise 8: Read a csv file and analyze the Data

Aim

To Write a program to read a csv file and analyze the data in the file
in R.

Procedure

Step 1: Start the program


Step 2: Read the CSV File into R

data <- read.csv("D:/ex.csv")

Step 3: Inspect the Data

str(data)
summary(data)
Step 4: Calculate the mean and Median
Step 5: Stop the Program

Exercise 9: Pie chart and Bar chart

Aim

To Create pie chart and bar chart using R program

Procedure

Step 1: Start the program

Step 2: Define the Data


slices <- c(10, 12, 4, 16, 8)

lbls <- c("US", "UK", "Australia", "Germany", "France")

Step 3: Create the Pie Chart use the pie function

Step 4: Create the Bar Chart use the barplot

Step 5: Display the result

Step 6: Stop the program

Exercise 10: Statistical analysis on the data

Aim

To Create a data set and do statistical analysis on the data using R


program

Procedure

Step 1: Start the program

Step 2: Load the Data : head(iris)


Step 3: Explore the Data

str(iris)

dim(iris)

summary(iris)

Step 4: Compute descriptive statistics for each numerical variable.

mean(iris$Sepal.Width)

median(iris$Sepal.Width)

sd(iris$Sepal.Width)

Step 5: Visualize the Data

boxplot(iris)

plot(iris)

Step 6: Stop the Process

Exercise 11: Recursive function

Aim

To write a R Program to find factorial of the given number using


recursive function.

Procedure

Step 1: Start the program

Step 2: Define the Recursive Function


factrec<-function(n)

Step 3: Get the user input N value

Step 4: Compute the Factorial

result<-factrec(number)
Step 5: Print the result
Step 6: Stop the program

Exercise 12: Count the number of even and odd numbers

Aim

To Write a R program to count the number of even and odd numbers


from array of N numbers.

Procedure

Step 1: Start the program

Step 2: Define the Array

array<-c(97,8,9,10,1,5,23,24)
Step 3: Identify Even Numbers

even<-sum(array%%2==0)
Step 4: Identify Odd Numbers

odd<-sum(array%%2==1)
Step 5: Print the results

Step 6: Stop the Program

You might also like