1.R Programs
1.R Programs
R program to find the maximum and the minimum value of a given vector
print('Original vector:')
print(nums)
print("Original Vectors:")
print(x)
print(sort(x))
print(sort(x, decreasing=TRUE))
3.Write a R program to compare two data frames to find the row(s) in first data frame that are not
present in second data frame.
df_90 = data.frame(
df_91 = data.frame(
print("Original Dataframes:")
print(df_90)
print(df_91)
print("Row(s) in first data frame that are not present in second data frame:")
print(setdiff(df_90,df_91))
4.Write an R program to extract first 10 English letter in lower case and last 10 letters in upper
case and extract letters between 22nd to 24th letters in uppercase.
t = head(letters, 10)
print(t)
t = tail(LETTERS, 10)
print(t)
e = tail(LETTERS[22:24])
print(e)
print("Sum:")
print(sum(x))
print("Mean:")
print(mean(x))
print("Product:")
print(prod(x))
6.Write an R program to create a simple bar plot of five subject’s marks.
barplot(marks,
xlab = "Marks",
ylab = "Subject",
col = "darkred",
horiz = FALSE)
7.Write an R program to create a Dataframes which contain details of 5 employees and display the
details in ascending order.
Gender=c("M","M","F","F","M"),
Age=c(23,22,25,26,32),
Designation=c("Clerk","Manager","Exective","CEO","ASSISTANT"),
SSN=c("123-34-2346","123-44-779","556-24-433","123-98-987","679-77-576")
print(Employees)
8.Write an R program to create a data frame using two given vectors and display the
duplicated elements and unique rows of the said data frame.
a = c(10,20,10,10,40,50,20,30)
b = c(10,30,10,20,0,50,30,30)
ab = data.frame(a,b)
print(ab)
print("Duplicate elements of the said data frame:")
print(duplicated(ab))
print(unique(ab))
9.Write an R program to change the first level of a factor with another level of a given factor.
print("Original vector:")
print(v)
f = factor(v)
print(f)
levels(f)[1] = "e"
print(f)
(Imp-Factors are the data objects which are used to categorize the data and store it as levels. They can
store both strings and integers. They are useful in the columns which have a limited number of unique
values. Like "Male, "Female" and True, False etc. They are useful in data analysis for statistical
modeling.
Factors are created using the factor () function by taking a vector as input.
levels provides access to the levels attribute of a variable. The first form returns the value of the levels
of its argument and the second sets the attribute.)
10.Write a script in R to create a list of cities and perform the following 1) Give names to the elements in
the list. 2) Add an element at the end of the list. 3) Remove the last element. 4) Update the 3rd Element