Академический Документы
Профессиональный Документы
Культура Документы
DATE: 28.2.2020
DATA ANALYTICS LAB
NAME : DATA TYPES and DATA FRAMES and READING FILES
Q4: Create two vectors. and perform multiplication of the two vectors and
store in a variable and then print
the contents of it
Sol:
v1 <- c(3,8,4,5,0,11)
v2 <- c(4,11,0,8,1,2)
result <- v1*v2
print(result)
Q5: Sort the vector created in the Q4 and store the sorted vector in a new
vector and print
Sol:
sorted <- sort(result)
print(sorted)
Sol:
# Create the data frame.
emp.data <- data.frame(
emp_id = c (1:5),
emp_name = c("Rick","Dan","Michelle","Ryan","Gary"),
salary = c(623.3,515.2,611.0,729.0,843.25),
Sol:
str(emp.data)
Q10: Write a R program to call the (built-in) dataset airquality. Remove the
variables 'Solar.R' and 'Wind' and display the data frame.
Sol:
data = airquality
print("Original data: Daily air quality measurements in New York, May to
September 1973.")
print(data)
data[,c("Solar.R")]=NULL
data[,c("Wind")]=NULL
print("data.frame after removing 'Solar.R' and 'Wind' variables:")
print(data)
Q10: Load the dataset mtcars into a variable. see the column names. display
the first 6 rows and last 6 rows of the cars (use head and tail)
Sol:
cars <-mtcars
cars
names(mtcars)
head(cars) # First 6 rows of dataset
tail(cars) # last 6 rows
head(cars, n=10)# First 10 rows of dataset cars
# check the following commans and see the output and explain
cars[1:10, ] # First 10 rows
cars[1:10,1 ] # First 10 rows
cars[1:10,1:3 ] # First 10 rows
edit(cars)
Q11:load the data set mtcars into a variable usercars and store that info
into a csv file named mba.csv
SOl:
usercars<-mtcars
usercars
write.csv(usercars, "mba.csv")