R Program3
R Program3
· Print the summary of all the variables of the dataset iris (Hint: Use function summary())
· Use duplicated() function to print the logical vector indicating the duplicate values present
in the dataset iris
Code:
Output:
5) Print the dataset airquality
· Print the structure of the dataset airquality
· Print the summary of all the variables of the dataset airquality (Hint: Use function
summary())
· Use the function is.na() to find whether any missing values are in the dataset airquality
· Print the indices of the missing values in the dataset airquality in column major
representation
· Print the indices of the missing values in the dataset airquality in row major representation
· Print indices of the missing values in row and column number-wise (Hint: Use function
which() and argument arr.ind = TRUE)
· Print the records without missing values in the dataset airquality using the function
complete.cases()
· Print the records without missing values in the dataset airquality using the function
na.omit()
· Print the records without missing values in the dataset airquality using the function
na.exclude()
· Print the records containing missing values in the dataset airquality using the function
complete.cases()
Code:
Output:
6)Consider a numeric vector x <- c(3,4,5,6,7,8)
· Write a command to recode the values less than 6 with zero in the vector x
· Write a command to recode the values that are less than 5 or greater than 6 with 50
· Write a command to recode the values less than 6 with NA in the vector x
· Write a command to recode the values that are less than 5 or greater than 6 with NA
· Write a command to recode the values less than 6 with “NA” (enclose with double quotes)
in the vector x
· Write a command to recode the values that are less than 5 or greater than 6 with “NA”
Code:
Output:
7)Consider the given vectors:
· Sort the values in vector A and put it in p (Hint: use function sort())
Code:
Output:
· The dataframes, buildings and surveydata have a common key variable called, “location”.
· Use the merge() function to merge the two dataframes by “location”, into a new dataframe
“buildingStats”.
Code:
Output:
· The dataframes, buildings and data now have corresponding variables called location, and
LocationID.
· Use the merge() function to merge the columns of the two dataframes by the corresponding
variables.
Ø Perform inner join, outer join, left outer join, right outer join, cross join and write the
outputs in all cases.
Code:
Output:
10)Merge the rows of the following two dataframes:
Code:
Output:
Code:
Output:
12) Read in the cars.txt dataset and call it car1. Make sure you use the "header=F" option to
specify that there are no column names associated with the dataset. Next, assign "speed" and
"dist" to be the first and second column names to the car1 dataset. Find the dimension and
structure of the dataset car1.
Code:
car1 <- read.table("C:\Users\sanna\Documents\SEM-4\FDA\R_programs/cars.txt", header = FALSE, skip =
3)
print("Dimensions of car1:")
print(dim(car1))
print("Structure of car1:")
print(str(car1))
13)Create a dataframe(dtf) which contains data on store location, account rep, number of
employees and monthly sales and obtain the following output.
b) Write R code to first sort the above data frame by salesrep as the primary sort in ascending
order and then by monthsales in descending order.
Code:
Output:
14) Create a matrix of 4 X 5 containing duplicate elements and print unique elements from it.
Code:
Output: