How to perform selection and indexing of data frame elements in R?

483    Asked by AishwaryaJhadav in Data Science , Asked on Jan 2, 2020
Answered by Aishwarya Jhadav

To perform such operations, we have to build a dataframe first

# Some made up weather data

days <- c('mon','tue','wed','thu','fri')

temp <- c(22.2,21,23,24.3,25)

rain <- c(TRUE, TRUE, FALSE, FALSE, TRUE)

# Pass in the vectors:

df <- data.frame(days,temp,rain)

df



We can select everything from first row

# Everything from first row

df[1,]


We can select everything from first column

df[,1]

mon tue wed thu fri



Your Answer

Interviews

Parent Categories