R Programming Slip

Write an R program to create a Data frames which contain details of 5 employees  and display the details in ascending order.

Q. Write an R program to create a Data frames which contain details of 5 employees  and display the details in ascending order.

Answer :

Employees = data.frame(Name=c("Anastasia S","Dima R","Katherine S", "JAMES A","LAURA MARTIN"),
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("Details of the employees:")
print(Employees)


Q. 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.

Answer:

a = c(10,20,10,10,40,50,20,30)
b = c(10,30,10,20,0,50,30,30)
print("Original data frame:")
ab = data.frame(a,b)
print(ab)
print("Duplicate elements of the said data frame:")
print(duplicated(ab))
print("Unique rows of the said data frame:")
print(unique(ab))


Q. Write an R program to change the first level of a factor with another level of a given factor. 

Answer:

v = c("a", "b", "a", "c", "b")
print("Original vector:")
print(v)
f = factor(v)
print("Factor of the said vector:")
print(f)
levels(f)[1] = "e"
print(f)

R Programming Slip R Programming Slip Reviewed by technical_saurabh on December 28, 2020 Rating: 5

No comments:

Powered by Blogger.