0% found this document useful (0 votes)
15 views1 page

Lecture11 indexingDF

The document provides a series of R commands for working with the built-in iris dataset, including commands to view the structure and summary of the data. It demonstrates how to isolate specific rows and columns, create subsets, and exclude certain variables. Additionally, it shows how to filter the dataset based on the species 'setosa'.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Lecture11 indexingDF

The document provides a series of R commands for working with the built-in iris dataset, including commands to view the structure and summary of the data. It demonstrates how to isolate specific rows and columns, create subsets, and exclude certain variables. Additionally, it shows how to filter the dataset based on the species 'setosa'.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

##Lets work with in-built R datasets

data(iris)
??iris

str(iris) #structure of data frame

summary(iris)

summary(iris)

#read in first 10 rows

head(iris,10)

## subset/isolate the first 6 rows in different data frame


df6=iris[1:6,]
str(df6)

##isloate first 2 columns


df2=iris[,1:2]
head(df2)
str(df2)

##isolate all rows and 2 columns


x=iris[, c("Sepal.Length", "Sepal.Width")]
str(x)

##subset once column


## without drop the x2 will be a vector
x2= iris[, 'Sepal.Length', drop=FALSE]
head(x2)

## select variables Sepal.Length, Petal.Length, Species


vars <- c("Sepal.Length", "Petal.Length", "Species")
nd <- iris[vars]
head(nd)
str(nd)

# exclude column Species


vars <- names(iris) %in% c("Species")
nd <- iris[!vars]
str(nd)
head(nd)

### exclude 3rd and 4th column


nd<- iris[c(-3,-4)]
head(nd)

##select a column value


## isolate all rows corresponding to species setosa

df_setosa=subset(iris,iris$Species=="setosa")
str(df_setosa)
summary(df_setosa)

You might also like