Select single column in a dataframe


Introduction

We have covered basics of dataframe or tibble here. If we only want to select single column of tibble for further processing we use the $ operator.

Procedure

We will be working with the following tibble:

 
# package for creating tibble
library(tibble)

# create tibble
basic_tibble <- tibble(
  Name = c("Anthony Stark", "Steve Rogers","Bruce Banner","Carol Denvers"),
  Age = c(45,115,47,80),
  `Alias Name` = c("Ironman","Captain America","Hulk","Captain Marvel")
  )

The tibble contains the following data:

basic tibble

We will select the Alias Name column.

Code

 
# refer procedure for definition of basic_tibble
View(basic_tibble$`Alias Name`)

The output of above code is:

alias

Conclusion

Thus we have successfully covered selecting single column in a dataframe.

References

  • https://r4ds.had.co.nz/