You are on page 1of 16

Foundation of Data Analytics

Lab Assaignment -1

Name:Gunda Laxmisai
Reg No:21MIS7119
Displaying and Sampling
 Open Rstudio/Rconsole

 In console, Print the dataset mtcars

 Print the strcture of the dataset


 What is the datatype of the datset?

 How many colmns and rows are there in the


dataset??

 What information (structure summary) you will get


from str() function?
Str function gives the summary of the data, str () function
in R Language is used for compactly displaying the internal structure of
a R object. It can display even the internal structure of large lists which
are nested. It provides one liner output for the basic R objects letting the
user know about the object and its constituents.

Column-1: names ,num: data types


 Print the row names
 Print the column names

 Print the number of columns in mtcars (Hint: Use


function - ncol)
 Print the number of rows (Hint: Use function -
nrow)

 Print all the elements of 2nd row

 Print all the elements of 2nd, 5th and 13th row

 Print the elements of rows from 15 to 20

 Print the elements of rows from 13 to 24, 28 and


30
 Print all odd indexed rows (rows 1,3,5,...) (Hint:
Use function - seq)

 Print all even indexed rows (rows 2,4,6,...)

 Print every 3rd row from 1st row (1,4,7,10..)

 Print first row and last row (Hint: Use function -


ncol)

 Print last 3 rows without using tail() function


 Print the elements of 3rd column

 Print the elements of column with name "wt"

 Print the elements of columns "mpg" and "qsec


 Print first three columns

 Print the elements of columns from 5 to 10


 Print the elements of columns from 3 to 7, 9 and
11

 Print all odd indexed columns (1,3,5,...)


 Print all even indexed columns (2,4,6,...)

 Print every 3rd column from 1st column


(1,4,7,10..)
 Print first column and last column

 Print last 3 columns


 Print first Row and 2nd and third column

 Print First, Second Row and Second and Third


Column

 Print element at 2nd row, third column

 Print all the rows having "mpg" value greater than


14

 Print all the rows having "hp" value less than 100
 Print all the rows having "disp" value is between
100 and 200

Attach and Detach Functions


 Find what attach() and detach() commands do?
The attach function allows to access variables of a
data.frame without calling the data.frame. The detach
function can be used to remove the attachment of a
data.frame, which was previously attached with the
attach function. Unload a package, which was previously
loaded with the library function.
Head and Tail Functions
 find what head() and tail() commands do
Head() - display the first n rows of a dataset or data
frame.
If head() is given without any parameter, then the
default value is 5
Tail() - displays the last n rows of a dataset or data
frame.
If tail() is given without any parameter, then the default
value is 5
 Use head() and tail() commands to display sample
observations of mtcars dataset

 Use head() command to Print first 10 observations

 Use tail() commands to Print last 15 observations

Sorting
• Sort the observations of dataset "mtcars" in increasing
order based on the values in the column "mpg"
• Sort the observations of dataset "mtcars" in
decreasing order based on the values in the column
"cyl"

• Sort the observations of dataset "mtcars" in


increasing order based on the values in the columns
both "mpg" and "cyl".
• Sort the observations of dataset "mtcars" in
decreasing order based on the values in the columns
both "mpg" and "cyl".
• Sort the observations of the dataset "mtcars" by
column "mpg" in increasing order and column "cyl" in
decreasing order

You might also like