Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

# Task 1: Perfrom the following tasks in the function data_handle_1

# A. Create 3 vector (name, age, department) with 5 observations each.


name <- c("A", "B", "C", "D", "E")
department <- c("AA", "BB", "CC" , "DD", "EE")
age <- c(10,11,12,13,14)

# B. Create a data frame empdetails using these three vectors.


empdetails_df <- data.frame(name , age,department )

# C. Print the data frame and view the structure of the data frame and print
it.
print(empdetails_df)
print(str(empdetails_df))

# Task 2: Perform the following tasks:


# A. View the structure in the dataset mtcars and print it.
print(str(mtcars))

# B. Print the summary of the dataset mtcars and print it.


print(summary(mtcars))

# Task 3: Print the first, second and tenth columns of the R build-in dataset
mtcars.
print(mtcars[, c(1, 2,10)])

# Task 4: Sort and Print mtcars by the column mpg.


print(mtcars[order(mtcars$mpg),])

#Task 5: From mtcars print details of all cars which provide more than 30
mpg.
task5 <- mtcars[mtcars$mpg > 30, ]
print(task5)

#Task 6: From mtcars and find all cars that provide more than 30 mpg, and print
the details of the cars in decreasing order of mileage.
# If there are two rows with same mileage, sort the two rows in decreasing
order of disp.
print(task5[rev(order(task5$mpg)),])

You might also like