R Bootcamp Day 2: Exploring the tidyverse

true

Goals

By the end of the day, you will:

  • Learn how to read in and examining Data
  • Begin understanding tidyverse “grammar”
  • Begin understanding the grammar of data manipulation, dplyr
  • Begin understanding what a pipe is and how to use pipes to chain together tidyverse verbs

0. Quick Refresher & Warm up

Before we get started with new content, let’s do a quick review of what we covered last time.

Exercise 0.1a

Create a vector, x, and make it the numbers 1 through 20. Change the 3rd and fourth element so that they are 5 times greater.

Last time, we ended by installing two packages, the rio package and the tidyverse package. This time, we’re going to learn how to use them to get our data into R, manipulate it, and visualize it. We’ll load them both now:

library(tidyverse)
## -- Attaching packages ------------------------------------------------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.1     v purrr   0.3.4
## v tibble  3.0.1     v dplyr   0.8.5
## v tidyr   1.1.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## -- Conflicts ---------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(rio)

1. Reading data into R

Now that we have the rio package and a basic idea of how packages work, let’s use it to read in some data! If you’re used to a GUI system like excel or SPSS, reading in data in R can be a little bit confusing at first.

Reading in data generally has two slightly challenging aspects for new users:

  1. You need to call a function that works with a particular data format (csv, txt, sav, etc.).

  2. You need to tell R where to look.

We’ll use import() from rio, which does the first part for us. We just call import() and it calls the right read function given the file’s extension (.csv, .txt, .sav, .xlsx, etc.).

1.1 Working Directories & File Paths

On to challeng # 2. When R looks for a file, it has a starting point. This is called the working directory. The working directory that you’re currently in is displayed in the console window and the files tab. You can also get it with the getwd() function:

getwd()
## [1] "C:/Users/coryc3133/OneDrive - Umich/Work/Costello-academic-site/content/courses/rbootcamp"

For this tutorial, your working directory should be wherever you downloaded the materials and opened the r project. If you opened the .Rmd, you should be in the uoregon_r_bootcamp directory already. You can change your working directory with:

setwd("PATH")

It is considered bad practice to use setwd() and it typically will not work in an Rmd; you can see the author’s rationale for that here.

My recommondation is to either:

  1. Use an R project. This is a relatively foolproof way of doing things.
  2. Use .Rmds and always open Rstudio from the particular Rmd. This is a little less foolproof.
  3. Use .Rmds and set the working directory in the console or through R Studio’s GUI. This is the least foolproof.

1 is probably best practice. 2 can save some time but may not be worth it. 3 is too risky for my tastes. If you do need to set the working directory from R Studio’s GUI, do the following:

Session > Set Working Directory > Choose Directory

You can choose the folder you want to work in. The code for setting the working directory will populate in the console. You can then copy/paste this into your code if you’d like.

1.2 Importing & Exporting data with rio

1.2.1 Importing Data

As I mentioned earlier, the import() function from rio really simplifies reading data into R. Let’s see that first hand by reading in the pragmatic_scales_data, a csv file:

library(rio)
ps_data <- import("pragmatic_scales_data.csv")

Let’s say that ps_data were a .sav SPSS data file. In rio, this is no problem, it will call the right function to read in .sav files. Let’s give it a try, reading in the pragmatic_scales_data.csv located in the data subdirectory of our current working directory:

ps_data <- import("data/ps_data.sav")

Notice that all I had to change was where to look (telling it to go to the data/ subdirectory and the file called ps_data.csv)

You can also import data from a website. For example, this dataset is also hosted on github, so we could download it from there using import() too:

ps_data <- import("https://raw.githubusercontent.com/Coryc3133/uoregon_r_bootcamp/master/pragmatic_scales_data.csv")

You can see all of the file formats rio works with by running ?import.

1.2.2 Exporting Data

You can also use rio to export your data, saving it in any of the formats that it works with. This is really simple and works just like import(), but is called export(). For export(), you provide the R dataframe object you want to export, and the path/name for the new file. For example, let’s say I want to export ps_data as an xlsx file and put it into the /data subdirectory. I could do that with export:

export(ps_data,
       "data/ps_data.xlsx")

Exercise 1.2a

I made a mistake when creating this and left the datasets in the uoregon_r_bootcamp folder instead of putting them into the /data directory. Let’s fix that. We already fixed ps_data, but now I want you to fix another_data_set.csv. First import the data as another_df:

Exercise 1.2b

Now I want you to export the data and save it into the data/ directory. Make sure the name of the dataframe is another_data_set, and make sure you save it out as a csv.

Exercise 1.2c

One of my colleagues insists we send them a .sav file so that they can run the analyses in SPSS. Make another copy of another_data_set in the data/ subdirectory that is in the .sav format.

Exercise 1.2d

Finally, let’s read one of these datasets to make sure everything worked as expected. Import the .sav version of another_data_set as another_df.

1.3 Examining Your Data

Now that your data is in R, you may want to take a look at it. There are a few different ways to do that, which each offer different information.

4.3.1 View

One way is to click on the View button in the environment pane. You should see ps_data in the environment pane with a little data icon at the far right. Click on that icon. You’ll notice that this ran View(ps_data) in the console. We can do that with code:

View(ps_data)

Note that the V in View() is capital!.

1.3.2 head and tail

You can also see just the first few rows of a dataframe with head():

head(ps_data)
##   subid   item correct  age condition
## 1   M22  faces       1 2.00     Label
## 2   M22 houses       1 2.00     Label
## 3   M22  pasta       0 2.00     Label
## 4   M22   beds       0 2.00     Label
## 5   T22   beds       0 2.13     Label
## 6   T22  faces       0 2.13     Label

This can be useful when you have very large datasets as it is much faster than the View function. head() prints 6 rows by default, but you can increase or decrease that with the n = argument. For example, imagine we want to see the first 20 rows:

head(ps_data, n = 20)
##    subid   item correct  age condition
## 1    M22  faces       1 2.00     Label
## 2    M22 houses       1 2.00     Label
## 3    M22  pasta       0 2.00     Label
## 4    M22   beds       0 2.00     Label
## 5    T22   beds       0 2.13     Label
## 6    T22  faces       0 2.13     Label
## 7    T22 houses       1 2.13     Label
## 8    T22  pasta       1 2.13     Label
## 9    T17  pasta       0 2.32     Label
## 10   T17  faces       0 2.32     Label
## 11   T17 houses       0 2.32     Label
## 12   T17   beds       0 2.32     Label
## 13    M3  faces       0 2.38     Label
## 14    M3 houses       1 2.38     Label
## 15    M3  pasta       1 2.38     Label
## 16    M3   beds       1 2.38     Label
## 17   T19  faces       0 2.47     Label
## 18   T19 houses       0 2.47     Label
## 19   T19  pasta       1 2.47     Label
## 20   T19   beds       1 2.47     Label

tail is the complement to head, displaying just the final rows from a dataframe:

tail(ps_data)
##      subid   item correct  age condition
## 583 MSCH84  pasta       1 2.83  No Label
## 584 MSCH84   beds       0 2.83  No Label
## 585 MSCH85  faces       0 2.69  No Label
## 586 MSCH85 houses       0 2.69  No Label
## 587 MSCH85  pasta       0 2.69  No Label
## 588 MSCH85   beds       0 2.69  No Label

1.3.3 Examine Structure with str

We saw str a little earlier when we first introduced dataframes. It’s worth mentioning it again because it can be so useful when you import data to see how the read function interpreted the variables. Let’s see:

str(ps_data)
## 'data.frame':    588 obs. of  5 variables:
##  $ subid    : chr  "M22" "M22" "M22" "M22" ...
##  $ item     : chr  "faces" "houses" "pasta" "beds" ...
##  $ correct  : int  1 1 0 0 0 0 1 1 0 0 ...
##  $ age      : num  2 2 2 2 2.13 2.13 2.13 2.13 2.32 2.32 ...
##  $ condition: chr  "Label" "Label" "Label" "Label" ...

1.3.4 Summary

The summary() funciton can be used to get a quick sense of each of the variables in a dataframe. It displays summary information for each variable. It displays different kinds of information depending on the variable’s type.

summary(ps_data)
##     subid               item              correct            age       
##  Length:588         Length:588         Min.   :0.0000   Min.   :2.000  
##  Class :character   Class :character   1st Qu.:0.0000   1st Qu.:2.850  
##  Mode  :character   Mode  :character   Median :0.0000   Median :3.460  
##                                        Mean   :0.4473   Mean   :3.525  
##                                        3rd Qu.:1.0000   3rd Qu.:4.290  
##                                        Max.   :1.0000   Max.   :4.960  
##   condition        
##  Length:588        
##  Class :character  
##  Mode  :character  
##                    
##                    
## 

2. More Advanced Indexing and Modifying a data frame in base R. (optional Content)

2.1 Indexing

Let’s start by reviewing indexing dataframes.

2.1.1 Bracket Indexing with Numerical Indices and Names

Recall that uou can select entries in the data frame just like indexing a matrix, i.e., [row, column]

ps_data[1, 5]
## [1] "Label"
ps_data[1, "condition"]
## [1] "Label"

And you can get a whole row or column by leaving the other dimension empty. Let’s get all rows of condition:

ps_data[, "condition"]
##   [1] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##   [7] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [13] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [19] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [25] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [31] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [37] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [43] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [49] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [55] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [61] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [67] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [73] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [79] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [85] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [91] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [97] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [103] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [109] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [115] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [121] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [127] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [133] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [139] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [145] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [151] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [157] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [163] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [169] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [175] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [181] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [187] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [193] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [199] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [205] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [211] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [217] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [223] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [229] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [235] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [241] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [247] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [253] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [259] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [265] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [271] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [277] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [283] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [289] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [295] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [301] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [307] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [313] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [319] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [325] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [331] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [337] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [343] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [349] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [355] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [361] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [367] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [373] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [379] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [385] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [391] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [397] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [403] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [409] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [415] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [421] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [427] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [433] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [439] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [445] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [451] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [457] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [463] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [469] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [475] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [481] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [487] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [493] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [499] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [505] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [511] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [517] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [523] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [529] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [535] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [541] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [547] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [553] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [559] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [565] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [571] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [577] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [583] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"

2.1.2 Indexing with $

Recall that you can also get a column from a df by using df$column. For example, we could get condition:

ps_data$condition
##   [1] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##   [7] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [13] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [19] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [25] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [31] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [37] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [43] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [49] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [55] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [61] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [67] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [73] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [79] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [85] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [91] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
##  [97] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [103] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [109] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [115] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [121] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [127] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [133] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [139] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [145] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [151] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [157] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [163] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [169] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [175] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [181] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [187] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [193] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [199] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [205] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [211] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [217] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [223] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [229] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [235] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [241] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [247] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [253] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [259] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [265] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [271] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [277] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [283] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [289] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [295] "Label"    "Label"    "Label"    "Label"    "Label"    "Label"   
## [301] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [307] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [313] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [319] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [325] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [331] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [337] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [343] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [349] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [355] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [361] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [367] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [373] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [379] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [385] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [391] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [397] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [403] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [409] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [415] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [421] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [427] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [433] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [439] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [445] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [451] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [457] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [463] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [469] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [475] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [481] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [487] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [493] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [499] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [505] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [511] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [517] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [523] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [529] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [535] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [541] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [547] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [553] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [559] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [565] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [571] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [577] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"
## [583] "No Label" "No Label" "No Label" "No Label" "No Label" "No Label"

2.1.3 Indexing with Logical Tests

Up to this point, we’ve only covered indexing by numerical index or name. But, you can also index via logical tests. To do this in base R, we use the which() function, which returns the indices where a condition is true. We can test if things are equal, not equal, greater, or lesser using the following symbols:

Test symbol
Equal ==
Not equal !=
Greater than >
Lesser than <
Greater than or Equal to >=
Lesser than or Equal to <=

Let’s put this to use and get all of the indices where condition is equal to label:

which(ps_data$condition == "Label")
##   [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18
##  [19]  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36
##  [37]  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54
##  [55]  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72
##  [73]  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90
##  [91]  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108
## [109] 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
## [127] 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
## [145] 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
## [163] 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
## [181] 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
## [199] 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
## [217] 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
## [235] 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
## [253] 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
## [271] 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
## [289] 289 290 291 292 293 294 295 296 297 298 299 300

We can combine this with [] indexing to do even more powerful subsetting. For example, we can put this which() call within the row position to extract the rows for subjects in the “Label” condition.

ps_data[which(ps_data$condition == "Label"),]
##     subid   item correct  age condition
## 1     M22  faces       1 2.00     Label
## 2     M22 houses       1 2.00     Label
## 3     M22  pasta       0 2.00     Label
## 4     M22   beds       0 2.00     Label
## 5     T22   beds       0 2.13     Label
## 6     T22  faces       0 2.13     Label
## 7     T22 houses       1 2.13     Label
## 8     T22  pasta       1 2.13     Label
## 9     T17  pasta       0 2.32     Label
## 10    T17  faces       0 2.32     Label
## 11    T17 houses       0 2.32     Label
## 12    T17   beds       0 2.32     Label
## 13     M3  faces       0 2.38     Label
## 14     M3 houses       1 2.38     Label
## 15     M3  pasta       1 2.38     Label
## 16     M3   beds       1 2.38     Label
## 17    T19  faces       0 2.47     Label
## 18    T19 houses       0 2.47     Label
## 19    T19  pasta       1 2.47     Label
## 20    T19   beds       1 2.47     Label
## 21    T20  faces       1 2.50     Label
## 22    T20 houses       1 2.50     Label
## 23    T20  pasta       0 2.50     Label
## 24    T20   beds       1 2.50     Label
## 25    T21  faces       1 2.58     Label
## 26    T21 houses       1 2.58     Label
## 27    T21  pasta       1 2.58     Label
## 28    T21   beds       0 2.58     Label
## 29    M26  faces       1 2.59     Label
## 30    M26 houses       1 2.59     Label
## 31    M26  pasta       0 2.59     Label
## 32    M26   beds       1 2.59     Label
## 33    T18  faces       1 2.61     Label
## 34    T18 houses       0 2.61     Label
## 35    T18  pasta       1 2.61     Label
## 36    T18   beds       0 2.61     Label
## 37    T12   beds       0 2.72     Label
## 38    T12  faces       0 2.72     Label
## 39    T12 houses       1 2.72     Label
## 40    T12  pasta       0 2.72     Label
## 41    T16  faces       1 2.73     Label
## 42    T16 houses       0 2.73     Label
## 43    T16  pasta       1 2.73     Label
## 44    T16   beds       1 2.73     Label
## 45     T7  faces       1 2.74     Label
## 46     T7 houses       0 2.74     Label
## 47     T7  pasta       0 2.74     Label
## 48     T7   beds       0 2.74     Label
## 49     T9 houses       0 2.79     Label
## 50     T9  faces       1 2.79     Label
## 51     T9  pasta       0 2.79     Label
## 52     T9   beds       1 2.79     Label
## 53     T5  faces       1 2.80     Label
## 54     T5 houses       1 2.80     Label
## 55     T5  pasta       0 2.80     Label
## 56     T5   beds       1 2.80     Label
## 57    T14  faces       1 2.83     Label
## 58    T14 houses       1 2.83     Label
## 59    T14  pasta       0 2.83     Label
## 60    T14   beds       1 2.83     Label
## 61     T2 houses       0 2.83     Label
## 62     T2  faces       0 2.83     Label
## 63     T2  pasta       1 2.83     Label
## 64     T2   beds       1 2.83     Label
## 65    T15  faces       0 2.85     Label
## 66    T15 houses       0 2.85     Label
## 67    T15  pasta       1 2.85     Label
## 68    T15   beds       0 2.85     Label
## 69    M13 houses       0 2.88     Label
## 70    M13   beds       1 2.88     Label
## 71    M13  faces       1 2.88     Label
## 72    M13  pasta       0 2.88     Label
## 73    M12  faces       1 2.88     Label
## 74    M12 houses       0 2.88     Label
## 75    M12  pasta       1 2.88     Label
## 76    M12   beds       0 2.88     Label
## 77    T13   beds       0 2.89     Label
## 78    T13  faces       0 2.89     Label
## 79    T13 houses       1 2.89     Label
## 80    T13  pasta       1 2.89     Label
## 81     T8  faces       1 2.91     Label
## 82     T8 houses       0 2.91     Label
## 83     T8  pasta       1 2.91     Label
## 84     T8   beds       1 2.91     Label
## 85     T1  faces       1 2.95     Label
## 86     T1 houses       0 2.95     Label
## 87     T1  pasta       0 2.95     Label
## 88     T1   beds       1 2.95     Label
## 89    M15  faces       1 2.98     Label
## 90    M15 houses       1 2.98     Label
## 91    M15  pasta       1 2.98     Label
## 92    M15   beds       1 2.98     Label
## 93    T11  faces       1 2.99     Label
## 94    T11 houses       0 2.99     Label
## 95    T11  pasta       1 2.99     Label
## 96    T11   beds       1 2.99     Label
## 97    T10  faces       0 3.00     Label
## 98    T10 houses       1 3.00     Label
## 99    T10  pasta       1 3.00     Label
## 100   T10   beds       1 3.00     Label
## 101    T3  faces       1 3.09     Label
## 102    T3 houses       1 3.09     Label
## 103    T3  pasta       1 3.09     Label
## 104    T3   beds       1 3.09     Label
## 105    T6  faces       1 3.10     Label
## 106    T6 houses       1 3.10     Label
## 107    T6  pasta       1 3.10     Label
## 108    T6   beds       1 3.10     Label
## 109   M32   beds       1 3.19     Label
## 110   M32  faces       1 3.19     Label
## 111   M32 houses       0 3.19     Label
## 112   M32  pasta       1 3.19     Label
## 113    M1  faces       0 3.20     Label
## 114    M1   beds       1 3.20     Label
## 115    M1  pasta       0 3.20     Label
## 116    M1 houses       0 3.20     Label
## 117   C16  faces       0 3.22     Label
## 118   C16 houses       0 3.22     Label
## 119   C16  pasta       1 3.22     Label
## 120   C16   beds       1 3.22     Label
## 121    T4  faces       1 3.24     Label
## 122    T4 houses       0 3.24     Label
## 123    T4  pasta       0 3.24     Label
## 124    T4   beds       1 3.24     Label
## 125   C17  faces       1 3.25     Label
## 126   C17 houses       0 3.25     Label
## 127   C17  pasta       1 3.25     Label
## 128   C17   beds       0 3.25     Label
## 129    C6  faces       0 3.26     Label
## 130    C6 houses       1 3.26     Label
## 131    C6  pasta       1 3.26     Label
## 132    C6   beds       1 3.26     Label
## 133   M10  faces       1 3.28     Label
## 134   M10 houses       1 3.28     Label
## 135   M10   beds       1 3.28     Label
## 136   M10  pasta       1 3.28     Label
## 137   M31  faces       0 3.30     Label
## 138   M31 houses       1 3.30     Label
## 139   M31  pasta       1 3.30     Label
## 140   M31   beds       1 3.30     Label
## 141    C3 houses       0 3.46     Label
## 142    C3  pasta       1 3.46     Label
## 143    C3   beds       1 3.46     Label
## 144    C3  faces       1 3.46     Label
## 145   C10  faces       0 3.46     Label
## 146   C10 houses       0 3.46     Label
## 147   C10  pasta       1 3.46     Label
## 148   C10   beds       1 3.46     Label
## 149   M18  faces       0 3.46     Label
## 150   M18 houses       1 3.46     Label
## 151   M18  pasta       1 3.46     Label
## 152   M18   beds       1 3.46     Label
## 153   M16  faces       0 3.50     Label
## 154   M16 houses       0 3.50     Label
## 155   M16  pasta       0 3.50     Label
## 156   M16   beds       1 3.50     Label
## 157   M23  faces       1 3.52     Label
## 158   M23 houses       0 3.52     Label
## 159   M23  pasta       1 3.52     Label
## 160   M23   beds       1 3.52     Label
## 161    C7  faces       0 3.55     Label
## 162    C7 houses       1 3.55     Label
## 163    C7  pasta       0 3.55     Label
## 164    C7   beds       0 3.55     Label
## 165   C12  faces       1 3.56     Label
## 166   C12 houses       0 3.56     Label
## 167   C12  pasta       1 3.56     Label
## 168   C12   beds       1 3.56     Label
## 169   C15  faces       1 3.59     Label
## 170   C15 houses       1 3.59     Label
## 171   C15  pasta       1 3.59     Label
## 172   C15   beds       1 3.59     Label
## 173   M29  faces       0 3.72     Label
## 174   M29 houses       1 3.72     Label
## 175   M29  pasta       1 3.72     Label
## 176   M29   beds       1 3.72     Label
## 177   C20  faces       1 3.75     Label
## 178   C20 houses       1 3.75     Label
## 179   C20  pasta       1 3.75     Label
## 180   C20   beds       1 3.75     Label
## 181   M11  faces       1 3.82     Label
## 182   M11 houses       0 3.82     Label
## 183   M11  pasta       1 3.82     Label
## 184   M11   beds       1 3.82     Label
## 185    C9   beds       1 3.82     Label
## 186    C9  faces       1 3.82     Label
## 187    C9 houses       1 3.82     Label
## 188    C9  pasta       1 3.82     Label
## 189   C24  faces       1 3.85     Label
## 190   C24 houses       0 3.85     Label
## 191   C24  pasta       0 3.85     Label
## 192   C24   beds       1 3.85     Label
## 193   C22  faces       0 3.92     Label
## 194   C22 houses       0 3.92     Label
## 195   C22  pasta       1 3.92     Label
## 196   C22   beds       1 3.92     Label
## 197    C8  faces       1 3.92     Label
## 198    C8 houses       1 3.92     Label
## 199    C8  pasta       1 3.92     Label
## 200    C8   beds       1 3.92     Label
## 201    M4  faces       1 3.96     Label
## 202    M4 houses       1 3.96     Label
## 203    M4  pasta       1 3.96     Label
## 204    M4   beds       1 3.96     Label
## 205    M6  faces       0 4.50     Label
## 206    M6 houses       1 4.50     Label
## 207    M6  pasta       1 4.50     Label
## 208    M6   beds       0 4.50     Label
## 209   C19  faces       1 4.14     Label
## 210   C19 houses       0 4.14     Label
## 211   C19  pasta       0 4.14     Label
## 212   C19   beds       1 4.14     Label
## 213    C1  faces       1 4.16     Label
## 214    C1 houses       1 4.16     Label
## 215    C1  pasta       1 4.16     Label
## 216    C1   beds       1 4.16     Label
## 217   M19   beds       1 4.16     Label
## 218   M19  faces       0 4.16     Label
## 219   M19 houses       0 4.16     Label
## 220   M19  pasta       1 4.16     Label
## 221   C11  faces       1 4.22     Label
## 222   C11 houses       0 4.22     Label
## 223   C11  pasta       1 4.22     Label
## 224   C11   beds       1 4.22     Label
## 225    M9  faces       1 4.26     Label
## 226    M9 houses       1 4.26     Label
## 227    M9  pasta       1 4.26     Label
## 228    M9   beds       1 4.26     Label
## 229    M2  faces       1 4.28     Label
## 230    M2 houses       0 4.28     Label
## 231    M2  pasta       1 4.28     Label
## 232    M2   beds       1 4.28     Label
## 233    C5  faces       1 4.29     Label
## 234    C5 houses       1 4.29     Label
## 235    C5  pasta       1 4.29     Label
## 236    C5   beds       1 4.29     Label
## 237   M30   beds       1 4.33     Label
## 238   M30  faces       1 4.33     Label
## 239   M30 houses       0 4.33     Label
## 240   M30  pasta       1 4.33     Label
## 241   C13  faces       0 4.38     Label
## 242   C13 houses       1 4.38     Label
## 243   C13  pasta       0 4.38     Label
## 244   C13   beds       1 4.38     Label
## 245    C4  faces       1 4.55     Label
## 246    C4 houses       1 4.55     Label
## 247    C4  pasta       1 4.55     Label
## 248    C4   beds       1 4.55     Label
## 249   C14  faces       1 4.57     Label
## 250   C14 houses       1 4.57     Label
## 251   C14  pasta       0 4.57     Label
## 252   C14   beds       1 4.57     Label
## 253   M17  faces       1 4.58     Label
## 254   M17 houses       1 4.58     Label
## 255   M17  pasta       1 4.58     Label
## 256   M17   beds       1 4.58     Label
## 257    C2  faces       1 4.60     Label
## 258    C2 houses       1 4.60     Label
## 259    C2  pasta       1 4.60     Label
## 260    C2   beds       1 4.60     Label
## 261   C23  faces       0 4.62     Label
## 262   C23 houses       1 4.62     Label
## 263   C23  pasta       1 4.62     Label
## 264   C23   beds       0 4.62     Label
## 265   M20  faces       0 4.64     Label
## 266   M20 houses       0 4.64     Label
## 267   M20  pasta       1 4.64     Label
## 268   M20   beds       1 4.64     Label
## 269   M21  faces       1 4.64     Label
## 270   M21 houses       1 4.64     Label
## 271   M21  pasta       1 4.64     Label
## 272   M21   beds       1 4.64     Label
## 273   C21  faces       1 4.73     Label
## 274   C21 houses       0 4.73     Label
## 275   C21  pasta       1 4.73     Label
## 276   C21   beds       1 4.73     Label
## 277   M24  faces       1 4.82     Label
## 278   M24 houses       1 4.82     Label
## 279   M24  pasta       1 4.82     Label
## 280   M24   beds       1 4.82     Label
## 281    M5  faces       0 4.84     Label
## 282    M5 houses       0 4.84     Label
## 283    M5  pasta       0 4.84     Label
## 284    M5   beds       1 4.84     Label
## 285    M7  faces       1 4.89     Label
## 286    M7 houses       1 4.89     Label
## 287    M7  pasta       1 4.89     Label
## 288    M7   beds       0 4.89     Label
## 289    M8  faces       1 4.89     Label
## 290    M8 houses       1 4.89     Label
## 291    M8  pasta       1 4.89     Label
## 292    M8   beds       1 4.89     Label
## 293   C18  faces       0 4.95     Label
## 294   C18 houses       1 4.95     Label
## 295   C18  pasta       1 4.95     Label
## 296   C18   beds       1 4.95     Label
## 297   M25  faces       1 4.96     Label
## 298   M25 houses       1 4.96     Label
## 299   M25  pasta       1 4.96     Label
## 300   M25   beds       1 4.96     Label

Or, we could get all of the rows where subjects are greater than or equal to 2.5 years old:

ps_data[which(ps_data$age >= 2.5),]
##      subid   item correct  age condition
## 21     T20  faces       1 2.50     Label
## 22     T20 houses       1 2.50     Label
## 23     T20  pasta       0 2.50     Label
## 24     T20   beds       1 2.50     Label
## 25     T21  faces       1 2.58     Label
## 26     T21 houses       1 2.58     Label
## 27     T21  pasta       1 2.58     Label
## 28     T21   beds       0 2.58     Label
## 29     M26  faces       1 2.59     Label
## 30     M26 houses       1 2.59     Label
## 31     M26  pasta       0 2.59     Label
## 32     M26   beds       1 2.59     Label
## 33     T18  faces       1 2.61     Label
## 34     T18 houses       0 2.61     Label
## 35     T18  pasta       1 2.61     Label
## 36     T18   beds       0 2.61     Label
## 37     T12   beds       0 2.72     Label
## 38     T12  faces       0 2.72     Label
## 39     T12 houses       1 2.72     Label
## 40     T12  pasta       0 2.72     Label
## 41     T16  faces       1 2.73     Label
## 42     T16 houses       0 2.73     Label
## 43     T16  pasta       1 2.73     Label
## 44     T16   beds       1 2.73     Label
## 45      T7  faces       1 2.74     Label
## 46      T7 houses       0 2.74     Label
## 47      T7  pasta       0 2.74     Label
## 48      T7   beds       0 2.74     Label
## 49      T9 houses       0 2.79     Label
## 50      T9  faces       1 2.79     Label
## 51      T9  pasta       0 2.79     Label
## 52      T9   beds       1 2.79     Label
## 53      T5  faces       1 2.80     Label
## 54      T5 houses       1 2.80     Label
## 55      T5  pasta       0 2.80     Label
## 56      T5   beds       1 2.80     Label
## 57     T14  faces       1 2.83     Label
## 58     T14 houses       1 2.83     Label
## 59     T14  pasta       0 2.83     Label
## 60     T14   beds       1 2.83     Label
## 61      T2 houses       0 2.83     Label
## 62      T2  faces       0 2.83     Label
## 63      T2  pasta       1 2.83     Label
## 64      T2   beds       1 2.83     Label
## 65     T15  faces       0 2.85     Label
## 66     T15 houses       0 2.85     Label
## 67     T15  pasta       1 2.85     Label
## 68     T15   beds       0 2.85     Label
## 69     M13 houses       0 2.88     Label
## 70     M13   beds       1 2.88     Label
## 71     M13  faces       1 2.88     Label
## 72     M13  pasta       0 2.88     Label
## 73     M12  faces       1 2.88     Label
## 74     M12 houses       0 2.88     Label
## 75     M12  pasta       1 2.88     Label
## 76     M12   beds       0 2.88     Label
## 77     T13   beds       0 2.89     Label
## 78     T13  faces       0 2.89     Label
## 79     T13 houses       1 2.89     Label
## 80     T13  pasta       1 2.89     Label
## 81      T8  faces       1 2.91     Label
## 82      T8 houses       0 2.91     Label
## 83      T8  pasta       1 2.91     Label
## 84      T8   beds       1 2.91     Label
## 85      T1  faces       1 2.95     Label
## 86      T1 houses       0 2.95     Label
## 87      T1  pasta       0 2.95     Label
## 88      T1   beds       1 2.95     Label
## 89     M15  faces       1 2.98     Label
## 90     M15 houses       1 2.98     Label
## 91     M15  pasta       1 2.98     Label
## 92     M15   beds       1 2.98     Label
## 93     T11  faces       1 2.99     Label
## 94     T11 houses       0 2.99     Label
## 95     T11  pasta       1 2.99     Label
## 96     T11   beds       1 2.99     Label
## 97     T10  faces       0 3.00     Label
## 98     T10 houses       1 3.00     Label
## 99     T10  pasta       1 3.00     Label
## 100    T10   beds       1 3.00     Label
## 101     T3  faces       1 3.09     Label
## 102     T3 houses       1 3.09     Label
## 103     T3  pasta       1 3.09     Label
## 104     T3   beds       1 3.09     Label
## 105     T6  faces       1 3.10     Label
## 106     T6 houses       1 3.10     Label
## 107     T6  pasta       1 3.10     Label
## 108     T6   beds       1 3.10     Label
## 109    M32   beds       1 3.19     Label
## 110    M32  faces       1 3.19     Label
## 111    M32 houses       0 3.19     Label
## 112    M32  pasta       1 3.19     Label
## 113     M1  faces       0 3.20     Label
## 114     M1   beds       1 3.20     Label
## 115     M1  pasta       0 3.20     Label
## 116     M1 houses       0 3.20     Label
## 117    C16  faces       0 3.22     Label
## 118    C16 houses       0 3.22     Label
## 119    C16  pasta       1 3.22     Label
## 120    C16   beds       1 3.22     Label
## 121     T4  faces       1 3.24     Label
## 122     T4 houses       0 3.24     Label
## 123     T4  pasta       0 3.24     Label
## 124     T4   beds       1 3.24     Label
## 125    C17  faces       1 3.25     Label
## 126    C17 houses       0 3.25     Label
## 127    C17  pasta       1 3.25     Label
## 128    C17   beds       0 3.25     Label
## 129     C6  faces       0 3.26     Label
## 130     C6 houses       1 3.26     Label
## 131     C6  pasta       1 3.26     Label
## 132     C6   beds       1 3.26     Label
## 133    M10  faces       1 3.28     Label
## 134    M10 houses       1 3.28     Label
## 135    M10   beds       1 3.28     Label
## 136    M10  pasta       1 3.28     Label
## 137    M31  faces       0 3.30     Label
## 138    M31 houses       1 3.30     Label
## 139    M31  pasta       1 3.30     Label
## 140    M31   beds       1 3.30     Label
## 141     C3 houses       0 3.46     Label
## 142     C3  pasta       1 3.46     Label
## 143     C3   beds       1 3.46     Label
## 144     C3  faces       1 3.46     Label
## 145    C10  faces       0 3.46     Label
## 146    C10 houses       0 3.46     Label
## 147    C10  pasta       1 3.46     Label
## 148    C10   beds       1 3.46     Label
## 149    M18  faces       0 3.46     Label
## 150    M18 houses       1 3.46     Label
## 151    M18  pasta       1 3.46     Label
## 152    M18   beds       1 3.46     Label
## 153    M16  faces       0 3.50     Label
## 154    M16 houses       0 3.50     Label
## 155    M16  pasta       0 3.50     Label
## 156    M16   beds       1 3.50     Label
## 157    M23  faces       1 3.52     Label
## 158    M23 houses       0 3.52     Label
## 159    M23  pasta       1 3.52     Label
## 160    M23   beds       1 3.52     Label
## 161     C7  faces       0 3.55     Label
## 162     C7 houses       1 3.55     Label
## 163     C7  pasta       0 3.55     Label
## 164     C7   beds       0 3.55     Label
## 165    C12  faces       1 3.56     Label
## 166    C12 houses       0 3.56     Label
## 167    C12  pasta       1 3.56     Label
## 168    C12   beds       1 3.56     Label
## 169    C15  faces       1 3.59     Label
## 170    C15 houses       1 3.59     Label
## 171    C15  pasta       1 3.59     Label
## 172    C15   beds       1 3.59     Label
## 173    M29  faces       0 3.72     Label
## 174    M29 houses       1 3.72     Label
## 175    M29  pasta       1 3.72     Label
## 176    M29   beds       1 3.72     Label
## 177    C20  faces       1 3.75     Label
## 178    C20 houses       1 3.75     Label
## 179    C20  pasta       1 3.75     Label
## 180    C20   beds       1 3.75     Label
## 181    M11  faces       1 3.82     Label
## 182    M11 houses       0 3.82     Label
## 183    M11  pasta       1 3.82     Label
## 184    M11   beds       1 3.82     Label
## 185     C9   beds       1 3.82     Label
## 186     C9  faces       1 3.82     Label
## 187     C9 houses       1 3.82     Label
## 188     C9  pasta       1 3.82     Label
## 189    C24  faces       1 3.85     Label
## 190    C24 houses       0 3.85     Label
## 191    C24  pasta       0 3.85     Label
## 192    C24   beds       1 3.85     Label
## 193    C22  faces       0 3.92     Label
## 194    C22 houses       0 3.92     Label
## 195    C22  pasta       1 3.92     Label
## 196    C22   beds       1 3.92     Label
## 197     C8  faces       1 3.92     Label
## 198     C8 houses       1 3.92     Label
## 199     C8  pasta       1 3.92     Label
## 200     C8   beds       1 3.92     Label
## 201     M4  faces       1 3.96     Label
## 202     M4 houses       1 3.96     Label
## 203     M4  pasta       1 3.96     Label
## 204     M4   beds       1 3.96     Label
## 205     M6  faces       0 4.50     Label
## 206     M6 houses       1 4.50     Label
## 207     M6  pasta       1 4.50     Label
## 208     M6   beds       0 4.50     Label
## 209    C19  faces       1 4.14     Label
## 210    C19 houses       0 4.14     Label
## 211    C19  pasta       0 4.14     Label
## 212    C19   beds       1 4.14     Label
## 213     C1  faces       1 4.16     Label
## 214     C1 houses       1 4.16     Label
## 215     C1  pasta       1 4.16     Label
## 216     C1   beds       1 4.16     Label
## 217    M19   beds       1 4.16     Label
## 218    M19  faces       0 4.16     Label
## 219    M19 houses       0 4.16     Label
## 220    M19  pasta       1 4.16     Label
## 221    C11  faces       1 4.22     Label
## 222    C11 houses       0 4.22     Label
## 223    C11  pasta       1 4.22     Label
## 224    C11   beds       1 4.22     Label
## 225     M9  faces       1 4.26     Label
## 226     M9 houses       1 4.26     Label
## 227     M9  pasta       1 4.26     Label
## 228     M9   beds       1 4.26     Label
## 229     M2  faces       1 4.28     Label
## 230     M2 houses       0 4.28     Label
## 231     M2  pasta       1 4.28     Label
## 232     M2   beds       1 4.28     Label
## 233     C5  faces       1 4.29     Label
## 234     C5 houses       1 4.29     Label
## 235     C5  pasta       1 4.29     Label
## 236     C5   beds       1 4.29     Label
## 237    M30   beds       1 4.33     Label
## 238    M30  faces       1 4.33     Label
## 239    M30 houses       0 4.33     Label
## 240    M30  pasta       1 4.33     Label
## 241    C13  faces       0 4.38     Label
## 242    C13 houses       1 4.38     Label
## 243    C13  pasta       0 4.38     Label
## 244    C13   beds       1 4.38     Label
## 245     C4  faces       1 4.55     Label
## 246     C4 houses       1 4.55     Label
## 247     C4  pasta       1 4.55     Label
## 248     C4   beds       1 4.55     Label
## 249    C14  faces       1 4.57     Label
## 250    C14 houses       1 4.57     Label
## 251    C14  pasta       0 4.57     Label
## 252    C14   beds       1 4.57     Label
## 253    M17  faces       1 4.58     Label
## 254    M17 houses       1 4.58     Label
## 255    M17  pasta       1 4.58     Label
## 256    M17   beds       1 4.58     Label
## 257     C2  faces       1 4.60     Label
## 258     C2 houses       1 4.60     Label
## 259     C2  pasta       1 4.60     Label
## 260     C2   beds       1 4.60     Label
## 261    C23  faces       0 4.62     Label
## 262    C23 houses       1 4.62     Label
## 263    C23  pasta       1 4.62     Label
## 264    C23   beds       0 4.62     Label
## 265    M20  faces       0 4.64     Label
## 266    M20 houses       0 4.64     Label
## 267    M20  pasta       1 4.64     Label
## 268    M20   beds       1 4.64     Label
## 269    M21  faces       1 4.64     Label
## 270    M21 houses       1 4.64     Label
## 271    M21  pasta       1 4.64     Label
## 272    M21   beds       1 4.64     Label
## 273    C21  faces       1 4.73     Label
## 274    C21 houses       0 4.73     Label
## 275    C21  pasta       1 4.73     Label
## 276    C21   beds       1 4.73     Label
## 277    M24  faces       1 4.82     Label
## 278    M24 houses       1 4.82     Label
## 279    M24  pasta       1 4.82     Label
## 280    M24   beds       1 4.82     Label
## 281     M5  faces       0 4.84     Label
## 282     M5 houses       0 4.84     Label
## 283     M5  pasta       0 4.84     Label
## 284     M5   beds       1 4.84     Label
## 285     M7  faces       1 4.89     Label
## 286     M7 houses       1 4.89     Label
## 287     M7  pasta       1 4.89     Label
## 288     M7   beds       0 4.89     Label
## 289     M8  faces       1 4.89     Label
## 290     M8 houses       1 4.89     Label
## 291     M8  pasta       1 4.89     Label
## 292     M8   beds       1 4.89     Label
## 293    C18  faces       0 4.95     Label
## 294    C18 houses       1 4.95     Label
## 295    C18  pasta       1 4.95     Label
## 296    C18   beds       1 4.95     Label
## 297    M25  faces       1 4.96     Label
## 298    M25 houses       1 4.96     Label
## 299    M25  pasta       1 4.96     Label
## 300    M25   beds       1 4.96     Label
## 317 MSCH52  faces       0 2.50  No Label
## 318 MSCH52 houses       1 2.50  No Label
## 319 MSCH52  pasta       0 2.50  No Label
## 320 MSCH52   beds       1 2.50  No Label
## 321 MSCH38  faces       0 2.59  No Label
## 322 MSCH38 houses       0 2.59  No Label
## 323 MSCH38  pasta       1 2.59  No Label
## 324 MSCH38   beds       0 2.59  No Label
## 325 MSCH43  faces       0 2.71  No Label
## 326 MSCH43 houses       0 2.71  No Label
## 327 MSCH43  pasta       0 2.71  No Label
## 328 MSCH43   beds       0 2.71  No Label
## 329 MSCH49  faces       0 2.88  No Label
## 330 MSCH49 houses       0 2.88  No Label
## 331 MSCH49  pasta       0 2.88  No Label
## 332 MSCH49   beds       0 2.88  No Label
## 333 MSCH45  faces       0 2.90  No Label
## 334 MSCH45 houses       0 2.90  No Label
## 335 MSCH45  pasta       0 2.90  No Label
## 336 MSCH45   beds       1 2.90  No Label
## 337 MSCH42  faces       1 2.93  No Label
## 338 MSCH42 houses       0 2.93  No Label
## 339 MSCH42  pasta       0 2.93  No Label
## 340 MSCH42   beds       0 2.93  No Label
## 341 MSCH53  faces       1 2.99  No Label
## 342 MSCH53 houses       1 2.99  No Label
## 343 MSCH53  pasta       0 2.99  No Label
## 344 MSCH53   beds       0 2.99  No Label
## 345  SCH35  faces       0 3.02  No Label
## 346  SCH35 houses       0 3.02  No Label
## 347  SCH35  pasta       0 3.02  No Label
## 348  SCH35   beds       0 3.02  No Label
## 349 MSCH40  faces       0 3.02  No Label
## 350 MSCH40 houses       1 3.02  No Label
## 351 MSCH40  pasta       0 3.02  No Label
## 352 MSCH40   beds       1 3.02  No Label
## 353  SCH34  faces       0 3.06  No Label
## 354  SCH34 houses       0 3.06  No Label
## 355  SCH34  pasta       0 3.06  No Label
## 356  SCH34   beds       0 3.06  No Label
## 357  SCH33  faces       0 3.06  No Label
## 358  SCH33 houses       0 3.06  No Label
## 359  SCH33  pasta       0 3.06  No Label
## 360  SCH33   beds       0 3.06  No Label
## 361 MSCH41  faces       0 3.18  No Label
## 362 MSCH41 houses       0 3.18  No Label
## 363 MSCH41  pasta       0 3.18  No Label
## 364 MSCH41   beds       0 3.18  No Label
## 365  SCH37   beds       0 3.27  No Label
## 366  SCH37  faces       1 3.27  No Label
## 367  SCH37 houses       0 3.27  No Label
## 368  SCH37  pasta       1 3.27  No Label
## 369  SCH32  faces       1 3.27  No Label
## 370  SCH32 houses       0 3.27  No Label
## 371  SCH32  pasta       0 3.27  No Label
## 372  SCH32   beds       0 3.27  No Label
## 373  SCH36   beds       0 3.33  No Label
## 374  SCH36  faces       0 3.33  No Label
## 375  SCH36 houses       1 3.33  No Label
## 376  SCH36  pasta       1 3.33  No Label
## 377  SCH11   beds       0 3.41  No Label
## 378  SCH12  faces       0 3.41  No Label
## 379  SCH12 houses       0 3.41  No Label
## 380  SCH12  pasta       0 3.41  No Label
## 381  SCH12   beds       0 3.41  No Label
## 382  SCH18  faces       0 3.45  No Label
## 383  SCH18 houses       0 3.45  No Label
## 384  SCH18  pasta       0 3.45  No Label
## 385  SCH18   beds       0 3.45  No Label
## 386 MSCH48  faces       0 3.50  No Label
## 387 MSCH48 houses       1 3.50  No Label
## 388 MSCH48  pasta       0 3.50  No Label
## 389 MSCH48   beds       0 3.50  No Label
## 390  SCH25  faces       0 3.54  No Label
## 391  SCH25 houses       1 3.54  No Label
## 392  SCH25  pasta       1 3.54  No Label
## 393  SCH25   beds       0 3.54  No Label
## 394  SCH31  faces       0 3.71  No Label
## 395  SCH31 houses       0 3.71  No Label
## 396  SCH31  pasta       0 3.71  No Label
## 397  SCH31   beds       0 3.71  No Label
## 398 MSCH46  faces       0 3.76  No Label
## 399 MSCH46 houses       0 3.76  No Label
## 400 MSCH46  pasta       1 3.76  No Label
## 401 MSCH46   beds       0 3.76  No Label
## 402  SCH11  faces       1 3.82  No Label
## 403  SCH11 houses       1 3.82  No Label
## 404  SCH11  pasta       1 3.82  No Label
## 405  SCH29  faces       0 3.83  No Label
## 406  SCH29 houses       0 3.83  No Label
## 407  SCH29  pasta       0 3.83  No Label
## 408  SCH29   beds       0 3.83  No Label
## 409 MSCH39   beds       1 3.93  No Label
## 410 MSCH39  pasta       0 3.93  No Label
## 411 MSCH39 houses       0 3.94  No Label
## 412 MSCH39  faces       0 3.94  No Label
## 413  SCH28  faces       0 4.02  No Label
## 414  SCH28 houses       0 4.02  No Label
## 415  SCH28  pasta       0 4.02  No Label
## 416  SCH28   beds       0 4.02  No Label
## 417  SCH22  faces       0 4.02  No Label
## 418  SCH22 houses       0 4.02  No Label
## 419  SCH22  pasta       0 4.02  No Label
## 420  SCH22   beds       1 4.02  No Label
## 421  SCH24  faces       0 4.07  No Label
## 422  SCH24 houses       0 4.07  No Label
## 423  SCH24  pasta       1 4.07  No Label
## 424  SCH24   beds       0 4.07  No Label
## 425  SCH27  faces       0 4.09  No Label
## 426  SCH27 houses       0 4.09  No Label
## 427  SCH27  pasta       1 4.09  No Label
## 428  SCH27   beds       0 4.09  No Label
## 429  SCH17  faces       0 4.25  No Label
## 430  SCH17 houses       0 4.25  No Label
## 431  SCH17  pasta       1 4.25  No Label
## 432  SCH17   beds       0 4.25  No Label
## 433  SCH10  faces       0 4.32  No Label
## 434  SCH10 houses       0 4.32  No Label
## 435  SCH10  pasta       0 4.32  No Label
## 436  SCH10   beds       1 4.32  No Label
## 437   SCH9  faces       0 4.37  No Label
## 438   SCH9 houses       0 4.37  No Label
## 439   SCH9  pasta       0 4.37  No Label
## 440   SCH9   beds       0 4.37  No Label
## 441  SCH20  faces       0 4.39  No Label
## 442  SCH20 houses       0 4.39  No Label
## 443  SCH20  pasta       0 4.39  No Label
## 444  SCH20   beds       0 4.39  No Label
## 445   SCH6  faces       0 4.41  No Label
## 446   SCH6 houses       0 4.41  No Label
## 447   SCH6  pasta       0 4.41  No Label
## 448   SCH6   beds       0 4.41  No Label
## 449   SCH7  faces       1 4.41  No Label
## 450   SCH7 houses       0 4.41  No Label
## 451   SCH7  pasta       0 4.41  No Label
## 452   SCH7   beds       0 4.41  No Label
## 453  SCH15  faces       1 4.42  No Label
## 454  SCH15 houses       0 4.42  No Label
## 455  SCH15  pasta       0 4.42  No Label
## 456  SCH15   beds       0 4.42  No Label
## 457  SCH30  faces       0 4.44  No Label
## 458  SCH30 houses       0 4.44  No Label
## 459  SCH30  pasta       1 4.44  No Label
## 460  SCH30   beds       0 4.44  No Label
## 461   SCH3  faces       0 4.47  No Label
## 462   SCH3 houses       0 4.47  No Label
## 463   SCH3  pasta       0 4.47  No Label
## 464   SCH3   beds       0 4.47  No Label
## 465  SCH26  faces       0 4.47  No Label
## 466  SCH26 houses       0 4.47  No Label
## 467  SCH26  pasta       1 4.47  No Label
## 468  SCH26   beds       0 4.47  No Label
## 469   SCH8  faces       0 4.52  No Label
## 470   SCH8 houses       0 4.52  No Label
## 471   SCH8  pasta       0 4.52  No Label
## 472   SCH8   beds       0 4.52  No Label
## 473  SCH16  faces       0 4.55  No Label
## 474  SCH16 houses       0 4.55  No Label
## 475  SCH16  pasta       0 4.55  No Label
## 476  SCH16   beds       1 4.55  No Label
## 477  SCH14  faces       0 4.58  No Label
## 478  SCH14 houses       0 4.58  No Label
## 479  SCH14  pasta       0 4.58  No Label
## 480  SCH14   beds       1 4.58  No Label
## 481   SCH2  faces       0 4.61  No Label
## 482   SCH2 houses       0 4.61  No Label
## 483   SCH2  pasta       0 4.61  No Label
## 484   SCH2   beds       0 4.61  No Label
## 485   SCH5  faces       0 4.61  No Label
## 486   SCH5 houses       0 4.61  No Label
## 487   SCH5  pasta       0 4.61  No Label
## 488   SCH5   beds       0 4.61  No Label
## 489  SCH13  faces       0 4.75  No Label
## 490  SCH13 houses       0 4.75  No Label
## 491  SCH13  pasta       0 4.75  No Label
## 492  SCH13   beds       0 4.75  No Label
## 493  SCH21  faces       0 4.76  No Label
## 494  SCH21 houses       0 4.76  No Label
## 495  SCH21  pasta       0 4.76  No Label
## 496  SCH21   beds       0 4.76  No Label
## 497  SCH19  faces       0 4.79  No Label
## 498  SCH19 houses       0 4.79  No Label
## 499  SCH19  pasta       0 4.79  No Label
## 500  SCH19   beds       1 4.79  No Label
## 501  SCH23  faces       0 4.82  No Label
## 502  SCH23 houses       0 4.82  No Label
## 503  SCH23  pasta       0 4.82  No Label
## 504  SCH23   beds       0 4.82  No Label
## 505   SCH1  faces       0 4.82  No Label
## 506   SCH1 houses       0 4.82  No Label
## 507   SCH1  pasta       0 4.82  No Label
## 508   SCH1   beds       0 4.82  No Label
## 509 MSCH66  faces       0 3.50  No Label
## 510 MSCH66 houses       0 3.50  No Label
## 511 MSCH66  pasta       1 3.50  No Label
## 512 MSCH66   beds       0 3.50  No Label
## 513 MSCH67  faces       0 3.24  No Label
## 514 MSCH67 houses       1 3.24  No Label
## 515 MSCH67  pasta       0 3.24  No Label
## 516 MSCH67   beds       1 3.24  No Label
## 517 MSCH68  faces       0 3.94  No Label
## 518 MSCH68 houses       0 3.94  No Label
## 519 MSCH68  pasta       0 3.94  No Label
## 520 MSCH68   beds       0 3.94  No Label
## 521 MSCH69  faces       0 2.72  No Label
## 522 MSCH69 houses       1 2.72  No Label
## 523 MSCH69  pasta       1 2.72  No Label
## 524 MSCH69   beds       0 2.72  No Label
## 529 MSCH71  faces       1 3.14  No Label
## 530 MSCH71 houses       1 3.14  No Label
## 531 MSCH71  pasta       1 3.14  No Label
## 532 MSCH71   beds       0 3.14  No Label
## 533 MSCH72  faces       1 3.72  No Label
## 534 MSCH72 houses       1 3.72  No Label
## 535 MSCH72  pasta       0 3.72  No Label
## 536 MSCH72   beds       0 3.72  No Label
## 537 MSCH73  faces       0 3.10  No Label
## 538 MSCH73 houses       0 3.10  No Label
## 539 MSCH73  pasta       0 3.10  No Label
## 540 MSCH73   beds       0 3.10  No Label
## 545 MSCH75  faces       0 3.67  No Label
## 546 MSCH75 houses       0 3.67  No Label
## 547 MSCH75  pasta       0 3.67  No Label
## 548 MSCH75   beds       0 3.66  No Label
## 549 MSCH76  faces       0 2.58  No Label
## 550 MSCH76 houses       0 2.58  No Label
## 551 MSCH76  pasta       0 2.58  No Label
## 552 MSCH76   beds       0 2.58  No Label
## 553 MSCH77  faces       0 2.55  No Label
## 554 MSCH77 houses       0 2.55  No Label
## 555 MSCH77  pasta       0 2.55  No Label
## 556 MSCH77   beds       1 2.55  No Label
## 561 MSCH79  faces       0 2.70  No Label
## 562 MSCH79 houses       1 2.70  No Label
## 563 MSCH79  pasta       0 2.70  No Label
## 564 MSCH79   beds       1 2.70  No Label
## 565 MSCH80  faces       0 2.76  No Label
## 566 MSCH80 houses       0 2.76  No Label
## 567 MSCH80  pasta       0 2.76  No Label
## 568 MSCH80   beds       0 2.76  No Label
## 569 MSCH81  faces       1 2.84  No Label
## 570 MSCH81 houses       0 2.84  No Label
## 571 MSCH81  pasta       0 2.84  No Label
## 572 MSCH81   beds       0 2.84  No Label
## 581 MSCH84  faces       0 2.83  No Label
## 582 MSCH84 houses       0 2.83  No Label
## 583 MSCH84  pasta       1 2.83  No Label
## 584 MSCH84   beds       0 2.83  No Label
## 585 MSCH85  faces       0 2.69  No Label
## 586 MSCH85 houses       0 2.69  No Label
## 587 MSCH85  pasta       0 2.69  No Label
## 588 MSCH85   beds       0 2.69  No Label

You can also use logical tests for columns, though that is a little trickier. Let’s get all of the columns that start with the letter c. We can look for variables that start with c by using str_detect() on the column names, looking for entries that start with c "^c".

ps_data[,grep("^c", colnames(ps_data))]
##     correct condition
## 1         1     Label
## 2         1     Label
## 3         0     Label
## 4         0     Label
## 5         0     Label
## 6         0     Label
## 7         1     Label
## 8         1     Label
## 9         0     Label
## 10        0     Label
## 11        0     Label
## 12        0     Label
## 13        0     Label
## 14        1     Label
## 15        1     Label
## 16        1     Label
## 17        0     Label
## 18        0     Label
## 19        1     Label
## 20        1     Label
## 21        1     Label
## 22        1     Label
## 23        0     Label
## 24        1     Label
## 25        1     Label
## 26        1     Label
## 27        1     Label
## 28        0     Label
## 29        1     Label
## 30        1     Label
## 31        0     Label
## 32        1     Label
## 33        1     Label
## 34        0     Label
## 35        1     Label
## 36        0     Label
## 37        0     Label
## 38        0     Label
## 39        1     Label
## 40        0     Label
## 41        1     Label
## 42        0     Label
## 43        1     Label
## 44        1     Label
## 45        1     Label
## 46        0     Label
## 47        0     Label
## 48        0     Label
## 49        0     Label
## 50        1     Label
## 51        0     Label
## 52        1     Label
## 53        1     Label
## 54        1     Label
## 55        0     Label
## 56        1     Label
## 57        1     Label
## 58        1     Label
## 59        0     Label
## 60        1     Label
## 61        0     Label
## 62        0     Label
## 63        1     Label
## 64        1     Label
## 65        0     Label
## 66        0     Label
## 67        1     Label
## 68        0     Label
## 69        0     Label
## 70        1     Label
## 71        1     Label
## 72        0     Label
## 73        1     Label
## 74        0     Label
## 75        1     Label
## 76        0     Label
## 77        0     Label
## 78        0     Label
## 79        1     Label
## 80        1     Label
## 81        1     Label
## 82        0     Label
## 83        1     Label
## 84        1     Label
## 85        1     Label
## 86        0     Label
## 87        0     Label
## 88        1     Label
## 89        1     Label
## 90        1     Label
## 91        1     Label
## 92        1     Label
## 93        1     Label
## 94        0     Label
## 95        1     Label
## 96        1     Label
## 97        0     Label
## 98        1     Label
## 99        1     Label
## 100       1     Label
## 101       1     Label
## 102       1     Label
## 103       1     Label
## 104       1     Label
## 105       1     Label
## 106       1     Label
## 107       1     Label
## 108       1     Label
## 109       1     Label
## 110       1     Label
## 111       0     Label
## 112       1     Label
## 113       0     Label
## 114       1     Label
## 115       0     Label
## 116       0     Label
## 117       0     Label
## 118       0     Label
## 119       1     Label
## 120       1     Label
## 121       1     Label
## 122       0     Label
## 123       0     Label
## 124       1     Label
## 125       1     Label
## 126       0     Label
## 127       1     Label
## 128       0     Label
## 129       0     Label
## 130       1     Label
## 131       1     Label
## 132       1     Label
## 133       1     Label
## 134       1     Label
## 135       1     Label
## 136       1     Label
## 137       0     Label
## 138       1     Label
## 139       1     Label
## 140       1     Label
## 141       0     Label
## 142       1     Label
## 143       1     Label
## 144       1     Label
## 145       0     Label
## 146       0     Label
## 147       1     Label
## 148       1     Label
## 149       0     Label
## 150       1     Label
## 151       1     Label
## 152       1     Label
## 153       0     Label
## 154       0     Label
## 155       0     Label
## 156       1     Label
## 157       1     Label
## 158       0     Label
## 159       1     Label
## 160       1     Label
## 161       0     Label
## 162       1     Label
## 163       0     Label
## 164       0     Label
## 165       1     Label
## 166       0     Label
## 167       1     Label
## 168       1     Label
## 169       1     Label
## 170       1     Label
## 171       1     Label
## 172       1     Label
## 173       0     Label
## 174       1     Label
## 175       1     Label
## 176       1     Label
## 177       1     Label
## 178       1     Label
## 179       1     Label
## 180       1     Label
## 181       1     Label
## 182       0     Label
## 183       1     Label
## 184       1     Label
## 185       1     Label
## 186       1     Label
## 187       1     Label
## 188       1     Label
## 189       1     Label
## 190       0     Label
## 191       0     Label
## 192       1     Label
## 193       0     Label
## 194       0     Label
## 195       1     Label
## 196       1     Label
## 197       1     Label
## 198       1     Label
## 199       1     Label
## 200       1     Label
## 201       1     Label
## 202       1     Label
## 203       1     Label
## 204       1     Label
## 205       0     Label
## 206       1     Label
## 207       1     Label
## 208       0     Label
## 209       1     Label
## 210       0     Label
## 211       0     Label
## 212       1     Label
## 213       1     Label
## 214       1     Label
## 215       1     Label
## 216       1     Label
## 217       1     Label
## 218       0     Label
## 219       0     Label
## 220       1     Label
## 221       1     Label
## 222       0     Label
## 223       1     Label
## 224       1     Label
## 225       1     Label
## 226       1     Label
## 227       1     Label
## 228       1     Label
## 229       1     Label
## 230       0     Label
## 231       1     Label
## 232       1     Label
## 233       1     Label
## 234       1     Label
## 235       1     Label
## 236       1     Label
## 237       1     Label
## 238       1     Label
## 239       0     Label
## 240       1     Label
## 241       0     Label
## 242       1     Label
## 243       0     Label
## 244       1     Label
## 245       1     Label
## 246       1     Label
## 247       1     Label
## 248       1     Label
## 249       1     Label
## 250       1     Label
## 251       0     Label
## 252       1     Label
## 253       1     Label
## 254       1     Label
## 255       1     Label
## 256       1     Label
## 257       1     Label
## 258       1     Label
## 259       1     Label
## 260       1     Label
## 261       0     Label
## 262       1     Label
## 263       1     Label
## 264       0     Label
## 265       0     Label
## 266       0     Label
## 267       1     Label
## 268       1     Label
## 269       1     Label
## 270       1     Label
## 271       1     Label
## 272       1     Label
## 273       1     Label
## 274       0     Label
## 275       1     Label
## 276       1     Label
## 277       1     Label
## 278       1     Label
## 279       1     Label
## 280       1     Label
## 281       0     Label
## 282       0     Label
## 283       0     Label
## 284       1     Label
## 285       1     Label
## 286       1     Label
## 287       1     Label
## 288       0     Label
## 289       1     Label
## 290       1     Label
## 291       1     Label
## 292       1     Label
## 293       0     Label
## 294       1     Label
## 295       1     Label
## 296       1     Label
## 297       1     Label
## 298       1     Label
## 299       1     Label
## 300       1     Label
## 301       1  No Label
## 302       0  No Label
## 303       1  No Label
## 304       0  No Label
## 305       0  No Label
## 306       0  No Label
## 307       0  No Label
## 308       0  No Label
## 309       0  No Label
## 310       0  No Label
## 311       0  No Label
## 312       0  No Label
## 313       0  No Label
## 314       0  No Label
## 315       0  No Label
## 316       0  No Label
## 317       0  No Label
## 318       1  No Label
## 319       0  No Label
## 320       1  No Label
## 321       0  No Label
## 322       0  No Label
## 323       1  No Label
## 324       0  No Label
## 325       0  No Label
## 326       0  No Label
## 327       0  No Label
## 328       0  No Label
## 329       0  No Label
## 330       0  No Label
## 331       0  No Label
## 332       0  No Label
## 333       0  No Label
## 334       0  No Label
## 335       0  No Label
## 336       1  No Label
## 337       1  No Label
## 338       0  No Label
## 339       0  No Label
## 340       0  No Label
## 341       1  No Label
## 342       1  No Label
## 343       0  No Label
## 344       0  No Label
## 345       0  No Label
## 346       0  No Label
## 347       0  No Label
## 348       0  No Label
## 349       0  No Label
## 350       1  No Label
## 351       0  No Label
## 352       1  No Label
## 353       0  No Label
## 354       0  No Label
## 355       0  No Label
## 356       0  No Label
## 357       0  No Label
## 358       0  No Label
## 359       0  No Label
## 360       0  No Label
## 361       0  No Label
## 362       0  No Label
## 363       0  No Label
## 364       0  No Label
## 365       0  No Label
## 366       1  No Label
## 367       0  No Label
## 368       1  No Label
## 369       1  No Label
## 370       0  No Label
## 371       0  No Label
## 372       0  No Label
## 373       0  No Label
## 374       0  No Label
## 375       1  No Label
## 376       1  No Label
## 377       0  No Label
## 378       0  No Label
## 379       0  No Label
## 380       0  No Label
## 381       0  No Label
## 382       0  No Label
## 383       0  No Label
## 384       0  No Label
## 385       0  No Label
## 386       0  No Label
## 387       1  No Label
## 388       0  No Label
## 389       0  No Label
## 390       0  No Label
## 391       1  No Label
## 392       1  No Label
## 393       0  No Label
## 394       0  No Label
## 395       0  No Label
## 396       0  No Label
## 397       0  No Label
## 398       0  No Label
## 399       0  No Label
## 400       1  No Label
## 401       0  No Label
## 402       1  No Label
## 403       1  No Label
## 404       1  No Label
## 405       0  No Label
## 406       0  No Label
## 407       0  No Label
## 408       0  No Label
## 409       1  No Label
## 410       0  No Label
## 411       0  No Label
## 412       0  No Label
## 413       0  No Label
## 414       0  No Label
## 415       0  No Label
## 416       0  No Label
## 417       0  No Label
## 418       0  No Label
## 419       0  No Label
## 420       1  No Label
## 421       0  No Label
## 422       0  No Label
## 423       1  No Label
## 424       0  No Label
## 425       0  No Label
## 426       0  No Label
## 427       1  No Label
## 428       0  No Label
## 429       0  No Label
## 430       0  No Label
## 431       1  No Label
## 432       0  No Label
## 433       0  No Label
## 434       0  No Label
## 435       0  No Label
## 436       1  No Label
## 437       0  No Label
## 438       0  No Label
## 439       0  No Label
## 440       0  No Label
## 441       0  No Label
## 442       0  No Label
## 443       0  No Label
## 444       0  No Label
## 445       0  No Label
## 446       0  No Label
## 447       0  No Label
## 448       0  No Label
## 449       1  No Label
## 450       0  No Label
## 451       0  No Label
## 452       0  No Label
## 453       1  No Label
## 454       0  No Label
## 455       0  No Label
## 456       0  No Label
## 457       0  No Label
## 458       0  No Label
## 459       1  No Label
## 460       0  No Label
## 461       0  No Label
## 462       0  No Label
## 463       0  No Label
## 464       0  No Label
## 465       0  No Label
## 466       0  No Label
## 467       1  No Label
## 468       0  No Label
## 469       0  No Label
## 470       0  No Label
## 471       0  No Label
## 472       0  No Label
## 473       0  No Label
## 474       0  No Label
## 475       0  No Label
## 476       1  No Label
## 477       0  No Label
## 478       0  No Label
## 479       0  No Label
## 480       1  No Label
## 481       0  No Label
## 482       0  No Label
## 483       0  No Label
## 484       0  No Label
## 485       0  No Label
## 486       0  No Label
## 487       0  No Label
## 488       0  No Label
## 489       0  No Label
## 490       0  No Label
## 491       0  No Label
## 492       0  No Label
## 493       0  No Label
## 494       0  No Label
## 495       0  No Label
## 496       0  No Label
## 497       0  No Label
## 498       0  No Label
## 499       0  No Label
## 500       1  No Label
## 501       0  No Label
## 502       0  No Label
## 503       0  No Label
## 504       0  No Label
## 505       0  No Label
## 506       0  No Label
## 507       0  No Label
## 508       0  No Label
## 509       0  No Label
## 510       0  No Label
## 511       1  No Label
## 512       0  No Label
## 513       0  No Label
## 514       1  No Label
## 515       0  No Label
## 516       1  No Label
## 517       0  No Label
## 518       0  No Label
## 519       0  No Label
## 520       0  No Label
## 521       0  No Label
## 522       1  No Label
## 523       1  No Label
## 524       0  No Label
## 525       0  No Label
## 526       0  No Label
## 527       0  No Label
## 528       1  No Label
## 529       1  No Label
## 530       1  No Label
## 531       1  No Label
## 532       0  No Label
## 533       1  No Label
## 534       1  No Label
## 535       0  No Label
## 536       0  No Label
## 537       0  No Label
## 538       0  No Label
## 539       0  No Label
## 540       0  No Label
## 541       1  No Label
## 542       0  No Label
## 543       0  No Label
## 544       1  No Label
## 545       0  No Label
## 546       0  No Label
## 547       0  No Label
## 548       0  No Label
## 549       0  No Label
## 550       0  No Label
## 551       0  No Label
## 552       0  No Label
## 553       0  No Label
## 554       0  No Label
## 555       0  No Label
## 556       1  No Label
## 557       0  No Label
## 558       0  No Label
## 559       0  No Label
## 560       1  No Label
## 561       0  No Label
## 562       1  No Label
## 563       0  No Label
## 564       1  No Label
## 565       0  No Label
## 566       0  No Label
## 567       0  No Label
## 568       0  No Label
## 569       1  No Label
## 570       0  No Label
## 571       0  No Label
## 572       0  No Label
## 573       1  No Label
## 574       0  No Label
## 575       1  No Label
## 576       0  No Label
## 577       0  No Label
## 578       0  No Label
## 579       1  No Label
## 580       0  No Label
## 581       0  No Label
## 582       0  No Label
## 583       1  No Label
## 584       0  No Label
## 585       0  No Label
## 586       0  No Label
## 587       0  No Label
## 588       0  No Label

You can also do more complicated logical tests by including & for AND and | for OR. For example, let’s get subjects that were in the label condition and less than 3 years old:

ps_data[which(ps_data$condition == "Label" & ps_data$age < 3),]
##    subid   item correct  age condition
## 1    M22  faces       1 2.00     Label
## 2    M22 houses       1 2.00     Label
## 3    M22  pasta       0 2.00     Label
## 4    M22   beds       0 2.00     Label
## 5    T22   beds       0 2.13     Label
## 6    T22  faces       0 2.13     Label
## 7    T22 houses       1 2.13     Label
## 8    T22  pasta       1 2.13     Label
## 9    T17  pasta       0 2.32     Label
## 10   T17  faces       0 2.32     Label
## 11   T17 houses       0 2.32     Label
## 12   T17   beds       0 2.32     Label
## 13    M3  faces       0 2.38     Label
## 14    M3 houses       1 2.38     Label
## 15    M3  pasta       1 2.38     Label
## 16    M3   beds       1 2.38     Label
## 17   T19  faces       0 2.47     Label
## 18   T19 houses       0 2.47     Label
## 19   T19  pasta       1 2.47     Label
## 20   T19   beds       1 2.47     Label
## 21   T20  faces       1 2.50     Label
## 22   T20 houses       1 2.50     Label
## 23   T20  pasta       0 2.50     Label
## 24   T20   beds       1 2.50     Label
## 25   T21  faces       1 2.58     Label
## 26   T21 houses       1 2.58     Label
## 27   T21  pasta       1 2.58     Label
## 28   T21   beds       0 2.58     Label
## 29   M26  faces       1 2.59     Label
## 30   M26 houses       1 2.59     Label
## 31   M26  pasta       0 2.59     Label
## 32   M26   beds       1 2.59     Label
## 33   T18  faces       1 2.61     Label
## 34   T18 houses       0 2.61     Label
## 35   T18  pasta       1 2.61     Label
## 36   T18   beds       0 2.61     Label
## 37   T12   beds       0 2.72     Label
## 38   T12  faces       0 2.72     Label
## 39   T12 houses       1 2.72     Label
## 40   T12  pasta       0 2.72     Label
## 41   T16  faces       1 2.73     Label
## 42   T16 houses       0 2.73     Label
## 43   T16  pasta       1 2.73     Label
## 44   T16   beds       1 2.73     Label
## 45    T7  faces       1 2.74     Label
## 46    T7 houses       0 2.74     Label
## 47    T7  pasta       0 2.74     Label
## 48    T7   beds       0 2.74     Label
## 49    T9 houses       0 2.79     Label
## 50    T9  faces       1 2.79     Label
## 51    T9  pasta       0 2.79     Label
## 52    T9   beds       1 2.79     Label
## 53    T5  faces       1 2.80     Label
## 54    T5 houses       1 2.80     Label
## 55    T5  pasta       0 2.80     Label
## 56    T5   beds       1 2.80     Label
## 57   T14  faces       1 2.83     Label
## 58   T14 houses       1 2.83     Label
## 59   T14  pasta       0 2.83     Label
## 60   T14   beds       1 2.83     Label
## 61    T2 houses       0 2.83     Label
## 62    T2  faces       0 2.83     Label
## 63    T2  pasta       1 2.83     Label
## 64    T2   beds       1 2.83     Label
## 65   T15  faces       0 2.85     Label
## 66   T15 houses       0 2.85     Label
## 67   T15  pasta       1 2.85     Label
## 68   T15   beds       0 2.85     Label
## 69   M13 houses       0 2.88     Label
## 70   M13   beds       1 2.88     Label
## 71   M13  faces       1 2.88     Label
## 72   M13  pasta       0 2.88     Label
## 73   M12  faces       1 2.88     Label
## 74   M12 houses       0 2.88     Label
## 75   M12  pasta       1 2.88     Label
## 76   M12   beds       0 2.88     Label
## 77   T13   beds       0 2.89     Label
## 78   T13  faces       0 2.89     Label
## 79   T13 houses       1 2.89     Label
## 80   T13  pasta       1 2.89     Label
## 81    T8  faces       1 2.91     Label
## 82    T8 houses       0 2.91     Label
## 83    T8  pasta       1 2.91     Label
## 84    T8   beds       1 2.91     Label
## 85    T1  faces       1 2.95     Label
## 86    T1 houses       0 2.95     Label
## 87    T1  pasta       0 2.95     Label
## 88    T1   beds       1 2.95     Label
## 89   M15  faces       1 2.98     Label
## 90   M15 houses       1 2.98     Label
## 91   M15  pasta       1 2.98     Label
## 92   M15   beds       1 2.98     Label
## 93   T11  faces       1 2.99     Label
## 94   T11 houses       0 2.99     Label
## 95   T11  pasta       1 2.99     Label
## 96   T11   beds       1 2.99     Label

Or we might want subjects rows where the item is either faces or houses.

ps_data[which(ps_data$item == "faces" | ps_data$item == "houses"),]
##      subid   item correct  age condition
## 1      M22  faces       1 2.00     Label
## 2      M22 houses       1 2.00     Label
## 6      T22  faces       0 2.13     Label
## 7      T22 houses       1 2.13     Label
## 10     T17  faces       0 2.32     Label
## 11     T17 houses       0 2.32     Label
## 13      M3  faces       0 2.38     Label
## 14      M3 houses       1 2.38     Label
## 17     T19  faces       0 2.47     Label
## 18     T19 houses       0 2.47     Label
## 21     T20  faces       1 2.50     Label
## 22     T20 houses       1 2.50     Label
## 25     T21  faces       1 2.58     Label
## 26     T21 houses       1 2.58     Label
## 29     M26  faces       1 2.59     Label
## 30     M26 houses       1 2.59     Label
## 33     T18  faces       1 2.61     Label
## 34     T18 houses       0 2.61     Label
## 38     T12  faces       0 2.72     Label
## 39     T12 houses       1 2.72     Label
## 41     T16  faces       1 2.73     Label
## 42     T16 houses       0 2.73     Label
## 45      T7  faces       1 2.74     Label
## 46      T7 houses       0 2.74     Label
## 49      T9 houses       0 2.79     Label
## 50      T9  faces       1 2.79     Label
## 53      T5  faces       1 2.80     Label
## 54      T5 houses       1 2.80     Label
## 57     T14  faces       1 2.83     Label
## 58     T14 houses       1 2.83     Label
## 61      T2 houses       0 2.83     Label
## 62      T2  faces       0 2.83     Label
## 65     T15  faces       0 2.85     Label
## 66     T15 houses       0 2.85     Label
## 69     M13 houses       0 2.88     Label
## 71     M13  faces       1 2.88     Label
## 73     M12  faces       1 2.88     Label
## 74     M12 houses       0 2.88     Label
## 78     T13  faces       0 2.89     Label
## 79     T13 houses       1 2.89     Label
## 81      T8  faces       1 2.91     Label
## 82      T8 houses       0 2.91     Label
## 85      T1  faces       1 2.95     Label
## 86      T1 houses       0 2.95     Label
## 89     M15  faces       1 2.98     Label
## 90     M15 houses       1 2.98     Label
## 93     T11  faces       1 2.99     Label
## 94     T11 houses       0 2.99     Label
## 97     T10  faces       0 3.00     Label
## 98     T10 houses       1 3.00     Label
## 101     T3  faces       1 3.09     Label
## 102     T3 houses       1 3.09     Label
## 105     T6  faces       1 3.10     Label
## 106     T6 houses       1 3.10     Label
## 110    M32  faces       1 3.19     Label
## 111    M32 houses       0 3.19     Label
## 113     M1  faces       0 3.20     Label
## 116     M1 houses       0 3.20     Label
## 117    C16  faces       0 3.22     Label
## 118    C16 houses       0 3.22     Label
## 121     T4  faces       1 3.24     Label
## 122     T4 houses       0 3.24     Label
## 125    C17  faces       1 3.25     Label
## 126    C17 houses       0 3.25     Label
## 129     C6  faces       0 3.26     Label
## 130     C6 houses       1 3.26     Label
## 133    M10  faces       1 3.28     Label
## 134    M10 houses       1 3.28     Label
## 137    M31  faces       0 3.30     Label
## 138    M31 houses       1 3.30     Label
## 141     C3 houses       0 3.46     Label
## 144     C3  faces       1 3.46     Label
## 145    C10  faces       0 3.46     Label
## 146    C10 houses       0 3.46     Label
## 149    M18  faces       0 3.46     Label
## 150    M18 houses       1 3.46     Label
## 153    M16  faces       0 3.50     Label
## 154    M16 houses       0 3.50     Label
## 157    M23  faces       1 3.52     Label
## 158    M23 houses       0 3.52     Label
## 161     C7  faces       0 3.55     Label
## 162     C7 houses       1 3.55     Label
## 165    C12  faces       1 3.56     Label
## 166    C12 houses       0 3.56     Label
## 169    C15  faces       1 3.59     Label
## 170    C15 houses       1 3.59     Label
## 173    M29  faces       0 3.72     Label
## 174    M29 houses       1 3.72     Label
## 177    C20  faces       1 3.75     Label
## 178    C20 houses       1 3.75     Label
## 181    M11  faces       1 3.82     Label
## 182    M11 houses       0 3.82     Label
## 186     C9  faces       1 3.82     Label
## 187     C9 houses       1 3.82     Label
## 189    C24  faces       1 3.85     Label
## 190    C24 houses       0 3.85     Label
## 193    C22  faces       0 3.92     Label
## 194    C22 houses       0 3.92     Label
## 197     C8  faces       1 3.92     Label
## 198     C8 houses       1 3.92     Label
## 201     M4  faces       1 3.96     Label
## 202     M4 houses       1 3.96     Label
## 205     M6  faces       0 4.50     Label
## 206     M6 houses       1 4.50     Label
## 209    C19  faces       1 4.14     Label
## 210    C19 houses       0 4.14     Label
## 213     C1  faces       1 4.16     Label
## 214     C1 houses       1 4.16     Label
## 218    M19  faces       0 4.16     Label
## 219    M19 houses       0 4.16     Label
## 221    C11  faces       1 4.22     Label
## 222    C11 houses       0 4.22     Label
## 225     M9  faces       1 4.26     Label
## 226     M9 houses       1 4.26     Label
## 229     M2  faces       1 4.28     Label
## 230     M2 houses       0 4.28     Label
## 233     C5  faces       1 4.29     Label
## 234     C5 houses       1 4.29     Label
## 238    M30  faces       1 4.33     Label
## 239    M30 houses       0 4.33     Label
## 241    C13  faces       0 4.38     Label
## 242    C13 houses       1 4.38     Label
## 245     C4  faces       1 4.55     Label
## 246     C4 houses       1 4.55     Label
## 249    C14  faces       1 4.57     Label
## 250    C14 houses       1 4.57     Label
## 253    M17  faces       1 4.58     Label
## 254    M17 houses       1 4.58     Label
## 257     C2  faces       1 4.60     Label
## 258     C2 houses       1 4.60     Label
## 261    C23  faces       0 4.62     Label
## 262    C23 houses       1 4.62     Label
## 265    M20  faces       0 4.64     Label
## 266    M20 houses       0 4.64     Label
## 269    M21  faces       1 4.64     Label
## 270    M21 houses       1 4.64     Label
## 273    C21  faces       1 4.73     Label
## 274    C21 houses       0 4.73     Label
## 277    M24  faces       1 4.82     Label
## 278    M24 houses       1 4.82     Label
## 281     M5  faces       0 4.84     Label
## 282     M5 houses       0 4.84     Label
## 285     M7  faces       1 4.89     Label
## 286     M7 houses       1 4.89     Label
## 289     M8  faces       1 4.89     Label
## 290     M8 houses       1 4.89     Label
## 293    C18  faces       0 4.95     Label
## 294    C18 houses       1 4.95     Label
## 297    M25  faces       1 4.96     Label
## 298    M25 houses       1 4.96     Label
## 301 MSCH47  faces       1 2.01  No Label
## 302 MSCH47 houses       0 2.01  No Label
## 305 MSCH50  faces       0 2.03  No Label
## 306 MSCH50 houses       0 2.03  No Label
## 309 MSCH51  faces       0 2.07  No Label
## 310 MSCH51 houses       0 2.07  No Label
## 313 MSCH44  faces       0 2.25  No Label
## 314 MSCH44 houses       0 2.25  No Label
## 317 MSCH52  faces       0 2.50  No Label
## 318 MSCH52 houses       1 2.50  No Label
## 321 MSCH38  faces       0 2.59  No Label
## 322 MSCH38 houses       0 2.59  No Label
## 325 MSCH43  faces       0 2.71  No Label
## 326 MSCH43 houses       0 2.71  No Label
## 329 MSCH49  faces       0 2.88  No Label
## 330 MSCH49 houses       0 2.88  No Label
## 333 MSCH45  faces       0 2.90  No Label
## 334 MSCH45 houses       0 2.90  No Label
## 337 MSCH42  faces       1 2.93  No Label
## 338 MSCH42 houses       0 2.93  No Label
## 341 MSCH53  faces       1 2.99  No Label
## 342 MSCH53 houses       1 2.99  No Label
## 345  SCH35  faces       0 3.02  No Label
## 346  SCH35 houses       0 3.02  No Label
## 349 MSCH40  faces       0 3.02  No Label
## 350 MSCH40 houses       1 3.02  No Label
## 353  SCH34  faces       0 3.06  No Label
## 354  SCH34 houses       0 3.06  No Label
## 357  SCH33  faces       0 3.06  No Label
## 358  SCH33 houses       0 3.06  No Label
## 361 MSCH41  faces       0 3.18  No Label
## 362 MSCH41 houses       0 3.18  No Label
## 366  SCH37  faces       1 3.27  No Label
## 367  SCH37 houses       0 3.27  No Label
## 369  SCH32  faces       1 3.27  No Label
## 370  SCH32 houses       0 3.27  No Label
## 374  SCH36  faces       0 3.33  No Label
## 375  SCH36 houses       1 3.33  No Label
## 378  SCH12  faces       0 3.41  No Label
## 379  SCH12 houses       0 3.41  No Label
## 382  SCH18  faces       0 3.45  No Label
## 383  SCH18 houses       0 3.45  No Label
## 386 MSCH48  faces       0 3.50  No Label
## 387 MSCH48 houses       1 3.50  No Label
## 390  SCH25  faces       0 3.54  No Label
## 391  SCH25 houses       1 3.54  No Label
## 394  SCH31  faces       0 3.71  No Label
## 395  SCH31 houses       0 3.71  No Label
## 398 MSCH46  faces       0 3.76  No Label
## 399 MSCH46 houses       0 3.76  No Label
## 402  SCH11  faces       1 3.82  No Label
## 403  SCH11 houses       1 3.82  No Label
## 405  SCH29  faces       0 3.83  No Label
## 406  SCH29 houses       0 3.83  No Label
## 411 MSCH39 houses       0 3.94  No Label
## 412 MSCH39  faces       0 3.94  No Label
## 413  SCH28  faces       0 4.02  No Label
## 414  SCH28 houses       0 4.02  No Label
## 417  SCH22  faces       0 4.02  No Label
## 418  SCH22 houses       0 4.02  No Label
## 421  SCH24  faces       0 4.07  No Label
## 422  SCH24 houses       0 4.07  No Label
## 425  SCH27  faces       0 4.09  No Label
## 426  SCH27 houses       0 4.09  No Label
## 429  SCH17  faces       0 4.25  No Label
## 430  SCH17 houses       0 4.25  No Label
## 433  SCH10  faces       0 4.32  No Label
## 434  SCH10 houses       0 4.32  No Label
## 437   SCH9  faces       0 4.37  No Label
## 438   SCH9 houses       0 4.37  No Label
## 441  SCH20  faces       0 4.39  No Label
## 442  SCH20 houses       0 4.39  No Label
## 445   SCH6  faces       0 4.41  No Label
## 446   SCH6 houses       0 4.41  No Label
## 449   SCH7  faces       1 4.41  No Label
## 450   SCH7 houses       0 4.41  No Label
## 453  SCH15  faces       1 4.42  No Label
## 454  SCH15 houses       0 4.42  No Label
## 457  SCH30  faces       0 4.44  No Label
## 458  SCH30 houses       0 4.44  No Label
## 461   SCH3  faces       0 4.47  No Label
## 462   SCH3 houses       0 4.47  No Label
## 465  SCH26  faces       0 4.47  No Label
## 466  SCH26 houses       0 4.47  No Label
## 469   SCH8  faces       0 4.52  No Label
## 470   SCH8 houses       0 4.52  No Label
## 473  SCH16  faces       0 4.55  No Label
## 474  SCH16 houses       0 4.55  No Label
## 477  SCH14  faces       0 4.58  No Label
## 478  SCH14 houses       0 4.58  No Label
## 481   SCH2  faces       0 4.61  No Label
## 482   SCH2 houses       0 4.61  No Label
## 485   SCH5  faces       0 4.61  No Label
## 486   SCH5 houses       0 4.61  No Label
## 489  SCH13  faces       0 4.75  No Label
## 490  SCH13 houses       0 4.75  No Label
## 493  SCH21  faces       0 4.76  No Label
## 494  SCH21 houses       0 4.76  No Label
## 497  SCH19  faces       0 4.79  No Label
## 498  SCH19 houses       0 4.79  No Label
## 501  SCH23  faces       0 4.82  No Label
## 502  SCH23 houses       0 4.82  No Label
## 505   SCH1  faces       0 4.82  No Label
## 506   SCH1 houses       0 4.82  No Label
## 509 MSCH66  faces       0 3.50  No Label
## 510 MSCH66 houses       0 3.50  No Label
## 513 MSCH67  faces       0 3.24  No Label
## 514 MSCH67 houses       1 3.24  No Label
## 517 MSCH68  faces       0 3.94  No Label
## 518 MSCH68 houses       0 3.94  No Label
## 521 MSCH69  faces       0 2.72  No Label
## 522 MSCH69 houses       1 2.72  No Label
## 525 MSCH70  faces       0 2.31  No Label
## 526 MSCH70 houses       0 2.31  No Label
## 529 MSCH71  faces       1 3.14  No Label
## 530 MSCH71 houses       1 3.14  No Label
## 533 MSCH72  faces       1 3.72  No Label
## 534 MSCH72 houses       1 3.72  No Label
## 537 MSCH73  faces       0 3.10  No Label
## 538 MSCH73 houses       0 3.10  No Label
## 541 MSCH74  faces       1 2.34  No Label
## 542 MSCH74 houses       0 2.34  No Label
## 545 MSCH75  faces       0 3.67  No Label
## 546 MSCH75 houses       0 3.67  No Label
## 549 MSCH76  faces       0 2.58  No Label
## 550 MSCH76 houses       0 2.58  No Label
## 553 MSCH77  faces       0 2.55  No Label
## 554 MSCH77 houses       0 2.55  No Label
## 557 MSCH78  faces       0 2.43  No Label
## 558 MSCH78 houses       0 2.43  No Label
## 561 MSCH79  faces       0 2.70  No Label
## 562 MSCH79 houses       1 2.70  No Label
## 565 MSCH80  faces       0 2.76  No Label
## 566 MSCH80 houses       0 2.76  No Label
## 569 MSCH81  faces       1 2.84  No Label
## 570 MSCH81 houses       0 2.84  No Label
## 573 MSCH82  faces       1 2.46  No Label
## 574 MSCH82 houses       0 2.46  No Label
## 577 MSCH83  faces       0 2.37  No Label
## 578 MSCH83 houses       0 2.37  No Label
## 581 MSCH84  faces       0 2.83  No Label
## 582 MSCH84 houses       0 2.83  No Label
## 585 MSCH85  faces       0 2.69  No Label
## 586 MSCH85 houses       0 2.69  No Label

Exercise 2.1a

Get the first 10 rows of the item column from the ps_data df.

Exercise 2.1b

Using logical indexing, get all of the rows where age is greater than or equal to 3.5 and item equals “faces”.

Exercise 2.1c (Bonus)

Using logical indexing, get all of the columns that start with either s or a (Hint: you only need 1 grep call and | can be used within a string).

3. Introduction to the tidyverse

We installed and loaded the tidyverse earlier and now we’ll learn some of the basics. “The tidyverse is an opionated collection of R packages designed for data science”. It’s a suite of packages designed with a consistent philosophy and aesthetic. This is nice because all of the packages are designed to work well together, providing a consistent framework to do many of the most common tasks in R including:

  • data cleaning (tidyr)
  • data manipulating (dplyr)
  • data visualization (ggplot2)
  • working with strings (stringr)
  • working with factors (forcats)

Among others. We’ll be using functions from each of these packages today and tomorrow.

Today we’ll just focus on data manipulation with dplyr and data visualization with ggplot2

Three qualities of the tidyverse are worth mentioning at the outset:

  1. packages are designed to be like grammars for their task, so we’ll be using terms like verbs to discuss the tidyverse. The idea is that you can string these grammatical elements together to form more complex statements, just like with language.

  2. The first argument of (basically) every function is data. This is very handy, especially when it comes to piping (discussed below).

  3. Variable names are usually not quoted.

The last thing I want to be sure to mention is that the tidyverse packages all have helpful cheatsheets. I think these are one of the handiest R resources out there, and I look at them regularly.

Without further ado, let’s get started with some basic use of dplyr:

3.1 dplyr

dplyr is a grammar of data manipulation. It is made up of several verbs for common data manipulation tasks.

3.1.1 Selecting Columns

The select() is the first verb we’ll cover and is how we can subset columns. If you’re like me, you’ll soon find it much easier to use than the bracket subsetting we did earlier.

select() is the verb for selecting columns from a dataframe. The first argument is data followed which columns you would like to select.

3.1.1.1 Basics of Select

You can indicate the columns you want to select using unquoted names. For example, let’s select just age from ps_data

select(ps_data, age)
##      age
## 1   2.00
## 2   2.00
## 3   2.00
## 4   2.00
## 5   2.13
## 6   2.13
## 7   2.13
## 8   2.13
## 9   2.32
## 10  2.32
## 11  2.32
## 12  2.32
## 13  2.38
## 14  2.38
## 15  2.38
## 16  2.38
## 17  2.47
## 18  2.47
## 19  2.47
## 20  2.47
## 21  2.50
## 22  2.50
## 23  2.50
## 24  2.50
## 25  2.58
## 26  2.58
## 27  2.58
## 28  2.58
## 29  2.59
## 30  2.59
## 31  2.59
## 32  2.59
## 33  2.61
## 34  2.61
## 35  2.61
## 36  2.61
## 37  2.72
## 38  2.72
## 39  2.72
## 40  2.72
## 41  2.73
## 42  2.73
## 43  2.73
## 44  2.73
## 45  2.74
## 46  2.74
## 47  2.74
## 48  2.74
## 49  2.79
## 50  2.79
## 51  2.79
## 52  2.79
## 53  2.80
## 54  2.80
## 55  2.80
## 56  2.80
## 57  2.83
## 58  2.83
## 59  2.83
## 60  2.83
## 61  2.83
## 62  2.83
## 63  2.83
## 64  2.83
## 65  2.85
## 66  2.85
## 67  2.85
## 68  2.85
## 69  2.88
## 70  2.88
## 71  2.88
## 72  2.88
## 73  2.88
## 74  2.88
## 75  2.88
## 76  2.88
## 77  2.89
## 78  2.89
## 79  2.89
## 80  2.89
## 81  2.91
## 82  2.91
## 83  2.91
## 84  2.91
## 85  2.95
## 86  2.95
## 87  2.95
## 88  2.95
## 89  2.98
## 90  2.98
## 91  2.98
## 92  2.98
## 93  2.99
## 94  2.99
## 95  2.99
## 96  2.99
## 97  3.00
## 98  3.00
## 99  3.00
## 100 3.00
## 101 3.09
## 102 3.09
## 103 3.09
## 104 3.09
## 105 3.10
## 106 3.10
## 107 3.10
## 108 3.10
## 109 3.19
## 110 3.19
## 111 3.19
## 112 3.19
## 113 3.20
## 114 3.20
## 115 3.20
## 116 3.20
## 117 3.22
## 118 3.22
## 119 3.22
## 120 3.22
## 121 3.24
## 122 3.24
## 123 3.24
## 124 3.24
## 125 3.25
## 126 3.25
## 127 3.25
## 128 3.25
## 129 3.26
## 130 3.26
## 131 3.26
## 132 3.26
## 133 3.28
## 134 3.28
## 135 3.28
## 136 3.28
## 137 3.30
## 138 3.30
## 139 3.30
## 140 3.30
## 141 3.46
## 142 3.46
## 143 3.46
## 144 3.46
## 145 3.46
## 146 3.46
## 147 3.46
## 148 3.46
## 149 3.46
## 150 3.46
## 151 3.46
## 152 3.46
## 153 3.50
## 154 3.50
## 155 3.50
## 156 3.50
## 157 3.52
## 158 3.52
## 159 3.52
## 160 3.52
## 161 3.55
## 162 3.55
## 163 3.55
## 164 3.55
## 165 3.56
## 166 3.56
## 167 3.56
## 168 3.56
## 169 3.59
## 170 3.59
## 171 3.59
## 172 3.59
## 173 3.72
## 174 3.72
## 175 3.72
## 176 3.72
## 177 3.75
## 178 3.75
## 179 3.75
## 180 3.75
## 181 3.82
## 182 3.82
## 183 3.82
## 184 3.82
## 185 3.82
## 186 3.82
## 187 3.82
## 188 3.82
## 189 3.85
## 190 3.85
## 191 3.85
## 192 3.85
## 193 3.92
## 194 3.92
## 195 3.92
## 196 3.92
## 197 3.92
## 198 3.92
## 199 3.92
## 200 3.92
## 201 3.96
## 202 3.96
## 203 3.96
## 204 3.96
## 205 4.50
## 206 4.50
## 207 4.50
## 208 4.50
## 209 4.14
## 210 4.14
## 211 4.14
## 212 4.14
## 213 4.16
## 214 4.16
## 215 4.16
## 216 4.16
## 217 4.16
## 218 4.16
## 219 4.16
## 220 4.16
## 221 4.22
## 222 4.22
## 223 4.22
## 224 4.22
## 225 4.26
## 226 4.26
## 227 4.26
## 228 4.26
## 229 4.28
## 230 4.28
## 231 4.28
## 232 4.28
## 233 4.29
## 234 4.29
## 235 4.29
## 236 4.29
## 237 4.33
## 238 4.33
## 239 4.33
## 240 4.33
## 241 4.38
## 242 4.38
## 243 4.38
## 244 4.38
## 245 4.55
## 246 4.55
## 247 4.55
## 248 4.55
## 249 4.57
## 250 4.57
## 251 4.57
## 252 4.57
## 253 4.58
## 254 4.58
## 255 4.58
## 256 4.58
## 257 4.60
## 258 4.60
## 259 4.60
## 260 4.60
## 261 4.62
## 262 4.62
## 263 4.62
## 264 4.62
## 265 4.64
## 266 4.64
## 267 4.64
## 268 4.64
## 269 4.64
## 270 4.64
## 271 4.64
## 272 4.64
## 273 4.73
## 274 4.73
## 275 4.73
## 276 4.73
## 277 4.82
## 278 4.82
## 279 4.82
## 280 4.82
## 281 4.84
## 282 4.84
## 283 4.84
## 284 4.84
## 285 4.89
## 286 4.89
## 287 4.89
## 288 4.89
## 289 4.89
## 290 4.89
## 291 4.89
## 292 4.89
## 293 4.95
## 294 4.95
## 295 4.95
## 296 4.95
## 297 4.96
## 298 4.96
## 299 4.96
## 300 4.96
## 301 2.01
## 302 2.01
## 303 2.01
## 304 2.01
## 305 2.03
## 306 2.03
## 307 2.03
## 308 2.03
## 309 2.07
## 310 2.07
## 311 2.07
## 312 2.07
## 313 2.25
## 314 2.25
## 315 2.25
## 316 2.25
## 317 2.50
## 318 2.50
## 319 2.50
## 320 2.50
## 321 2.59
## 322 2.59
## 323 2.59
## 324 2.59
## 325 2.71
## 326 2.71
## 327 2.71
## 328 2.71
## 329 2.88
## 330 2.88
## 331 2.88
## 332 2.88
## 333 2.90
## 334 2.90
## 335 2.90
## 336 2.90
## 337 2.93
## 338 2.93
## 339 2.93
## 340 2.93
## 341 2.99
## 342 2.99
## 343 2.99
## 344 2.99
## 345 3.02
## 346 3.02
## 347 3.02
## 348 3.02
## 349 3.02
## 350 3.02
## 351 3.02
## 352 3.02
## 353 3.06
## 354 3.06
## 355 3.06
## 356 3.06
## 357 3.06
## 358 3.06
## 359 3.06
## 360 3.06
## 361 3.18
## 362 3.18
## 363 3.18
## 364 3.18
## 365 3.27
## 366 3.27
## 367 3.27
## 368 3.27
## 369 3.27
## 370 3.27
## 371 3.27
## 372 3.27
## 373 3.33
## 374 3.33
## 375 3.33
## 376 3.33
## 377 3.41
## 378 3.41
## 379 3.41
## 380 3.41
## 381 3.41
## 382 3.45
## 383 3.45
## 384 3.45
## 385 3.45
## 386 3.50
## 387 3.50
## 388 3.50
## 389 3.50
## 390 3.54
## 391 3.54
## 392 3.54
## 393 3.54
## 394 3.71
## 395 3.71
## 396 3.71
## 397 3.71
## 398 3.76
## 399 3.76
## 400 3.76
## 401 3.76
## 402 3.82
## 403 3.82
## 404 3.82
## 405 3.83
## 406 3.83
## 407 3.83
## 408 3.83
## 409 3.93
## 410 3.93
## 411 3.94
## 412 3.94
## 413 4.02
## 414 4.02
## 415 4.02
## 416 4.02
## 417 4.02
## 418 4.02
## 419 4.02
## 420 4.02
## 421 4.07
## 422 4.07
## 423 4.07
## 424 4.07
## 425 4.09
## 426 4.09
## 427 4.09
## 428 4.09
## 429 4.25
## 430 4.25
## 431 4.25
## 432 4.25
## 433 4.32
## 434 4.32
## 435 4.32
## 436 4.32
## 437 4.37
## 438 4.37
## 439 4.37
## 440 4.37
## 441 4.39
## 442 4.39
## 443 4.39
## 444 4.39
## 445 4.41
## 446 4.41
## 447 4.41
## 448 4.41
## 449 4.41
## 450 4.41
## 451 4.41
## 452 4.41
## 453 4.42
## 454 4.42
## 455 4.42
## 456 4.42
## 457 4.44
## 458 4.44
## 459 4.44
## 460 4.44
## 461 4.47
## 462 4.47
## 463 4.47
## 464 4.47
## 465 4.47
## 466 4.47
## 467 4.47
## 468 4.47
## 469 4.52
## 470 4.52
## 471 4.52
## 472 4.52
## 473 4.55
## 474 4.55
## 475 4.55
## 476 4.55
## 477 4.58
## 478 4.58
## 479 4.58
## 480 4.58
## 481 4.61
## 482 4.61
## 483 4.61
## 484 4.61
## 485 4.61
## 486 4.61
## 487 4.61
## 488 4.61
## 489 4.75
## 490 4.75
## 491 4.75
## 492 4.75
## 493 4.76
## 494 4.76
## 495 4.76
## 496 4.76
## 497 4.79
## 498 4.79
## 499 4.79
## 500 4.79
## 501 4.82
## 502 4.82
## 503 4.82
## 504 4.82
## 505 4.82
## 506 4.82
## 507 4.82
## 508 4.82
## 509 3.50
## 510 3.50
## 511 3.50
## 512 3.50
## 513 3.24
## 514 3.24
## 515 3.24
## 516 3.24
## 517 3.94
## 518 3.94
## 519 3.94
## 520 3.94
## 521 2.72
## 522 2.72
## 523 2.72
## 524 2.72
## 525 2.31
## 526 2.31
## 527 2.31
## 528 2.31
## 529 3.14
## 530 3.14
## 531 3.14
## 532 3.14
## 533 3.72
## 534 3.72
## 535 3.72
## 536 3.72
## 537 3.10
## 538 3.10
## 539 3.10
## 540 3.10
## 541 2.34
## 542 2.34
## 543 2.34
## 544 2.34
## 545 3.67
## 546 3.67
## 547 3.67
## 548 3.66
## 549 2.58
## 550 2.58
## 551 2.58
## 552 2.58
## 553 2.55
## 554 2.55
## 555 2.55
## 556 2.55
## 557 2.43
## 558 2.43
## 559 2.43
## 560 2.43
## 561 2.70
## 562 2.70
## 563 2.70
## 564 2.70
## 565 2.76
## 566 2.76
## 567 2.76
## 568 2.76
## 569 2.84
## 570 2.84
## 571 2.84
## 572 2.84
## 573 2.46
## 574 2.46
## 575 2.46
## 576 2.46
## 577 2.37
## 578 2.37
## 579 2.37
## 580 2.37
## 581 2.83
## 582 2.83
## 583 2.83
## 584 2.83
## 585 2.69
## 586 2.69
## 587 2.69
## 588 2.69

You can select more columns by enetring them, separated by a comma. Let’s get age and condition:

select(ps_data, age, condition)
##      age condition
## 1   2.00     Label
## 2   2.00     Label
## 3   2.00     Label
## 4   2.00     Label
## 5   2.13     Label
## 6   2.13     Label
## 7   2.13     Label
## 8   2.13     Label
## 9   2.32     Label
## 10  2.32     Label
## 11  2.32     Label
## 12  2.32     Label
## 13  2.38     Label
## 14  2.38     Label
## 15  2.38     Label
## 16  2.38     Label
## 17  2.47     Label
## 18  2.47     Label
## 19  2.47     Label
## 20  2.47     Label
## 21  2.50     Label
## 22  2.50     Label
## 23  2.50     Label
## 24  2.50     Label
## 25  2.58     Label
## 26  2.58     Label
## 27  2.58     Label
## 28  2.58     Label
## 29  2.59     Label
## 30  2.59     Label
## 31  2.59     Label
## 32  2.59     Label
## 33  2.61     Label
## 34  2.61     Label
## 35  2.61     Label
## 36  2.61     Label
## 37  2.72     Label
## 38  2.72     Label
## 39  2.72     Label
## 40  2.72     Label
## 41  2.73     Label
## 42  2.73     Label
## 43  2.73     Label
## 44  2.73     Label
## 45  2.74     Label
## 46  2.74     Label
## 47  2.74     Label
## 48  2.74     Label
## 49  2.79     Label
## 50  2.79     Label
## 51  2.79     Label
## 52  2.79     Label
## 53  2.80     Label
## 54  2.80     Label
## 55  2.80     Label
## 56  2.80     Label
## 57  2.83     Label
## 58  2.83     Label
## 59  2.83     Label
## 60  2.83     Label
## 61  2.83     Label
## 62  2.83     Label
## 63  2.83     Label
## 64  2.83     Label
## 65  2.85     Label
## 66  2.85     Label
## 67  2.85     Label
## 68  2.85     Label
## 69  2.88     Label
## 70  2.88     Label
## 71  2.88     Label
## 72  2.88     Label
## 73  2.88     Label
## 74  2.88     Label
## 75  2.88     Label
## 76  2.88     Label
## 77  2.89     Label
## 78  2.89     Label
## 79  2.89     Label
## 80  2.89     Label
## 81  2.91     Label
## 82  2.91     Label
## 83  2.91     Label
## 84  2.91     Label
## 85  2.95     Label
## 86  2.95     Label
## 87  2.95     Label
## 88  2.95     Label
## 89  2.98     Label
## 90  2.98     Label
## 91  2.98     Label
## 92  2.98     Label
## 93  2.99     Label
## 94  2.99     Label
## 95  2.99     Label
## 96  2.99     Label
## 97  3.00     Label
## 98  3.00     Label
## 99  3.00     Label
## 100 3.00     Label
## 101 3.09     Label
## 102 3.09     Label
## 103 3.09     Label
## 104 3.09     Label
## 105 3.10     Label
## 106 3.10     Label
## 107 3.10     Label
## 108 3.10     Label
## 109 3.19     Label
## 110 3.19     Label
## 111 3.19     Label
## 112 3.19     Label
## 113 3.20     Label
## 114 3.20     Label
## 115 3.20     Label
## 116 3.20     Label
## 117 3.22     Label
## 118 3.22     Label
## 119 3.22     Label
## 120 3.22     Label
## 121 3.24     Label
## 122 3.24     Label
## 123 3.24     Label
## 124 3.24     Label
## 125 3.25     Label
## 126 3.25     Label
## 127 3.25     Label
## 128 3.25     Label
## 129 3.26     Label
## 130 3.26     Label
## 131 3.26     Label
## 132 3.26     Label
## 133 3.28     Label
## 134 3.28     Label
## 135 3.28     Label
## 136 3.28     Label
## 137 3.30     Label
## 138 3.30     Label
## 139 3.30     Label
## 140 3.30     Label
## 141 3.46     Label
## 142 3.46     Label
## 143 3.46     Label
## 144 3.46     Label
## 145 3.46     Label
## 146 3.46     Label
## 147 3.46     Label
## 148 3.46     Label
## 149 3.46     Label
## 150 3.46     Label
## 151 3.46     Label
## 152 3.46     Label
## 153 3.50     Label
## 154 3.50     Label
## 155 3.50     Label
## 156 3.50     Label
## 157 3.52     Label
## 158 3.52     Label
## 159 3.52     Label
## 160 3.52     Label
## 161 3.55     Label
## 162 3.55     Label
## 163 3.55     Label
## 164 3.55     Label
## 165 3.56     Label
## 166 3.56     Label
## 167 3.56     Label
## 168 3.56     Label
## 169 3.59     Label
## 170 3.59     Label
## 171 3.59     Label
## 172 3.59     Label
## 173 3.72     Label
## 174 3.72     Label
## 175 3.72     Label
## 176 3.72     Label
## 177 3.75     Label
## 178 3.75     Label
## 179 3.75     Label
## 180 3.75     Label
## 181 3.82     Label
## 182 3.82     Label
## 183 3.82     Label
## 184 3.82     Label
## 185 3.82     Label
## 186 3.82     Label
## 187 3.82     Label
## 188 3.82     Label
## 189 3.85     Label
## 190 3.85     Label
## 191 3.85     Label
## 192 3.85     Label
## 193 3.92     Label
## 194 3.92     Label
## 195 3.92     Label
## 196 3.92     Label
## 197 3.92     Label
## 198 3.92     Label
## 199 3.92     Label
## 200 3.92     Label
## 201 3.96     Label
## 202 3.96     Label
## 203 3.96     Label
## 204 3.96     Label
## 205 4.50     Label
## 206 4.50     Label
## 207 4.50     Label
## 208 4.50     Label
## 209 4.14     Label
## 210 4.14     Label
## 211 4.14     Label
## 212 4.14     Label
## 213 4.16     Label
## 214 4.16     Label
## 215 4.16     Label
## 216 4.16     Label
## 217 4.16     Label
## 218 4.16     Label
## 219 4.16     Label
## 220 4.16     Label
## 221 4.22     Label
## 222 4.22     Label
## 223 4.22     Label
## 224 4.22     Label
## 225 4.26     Label
## 226 4.26     Label
## 227 4.26     Label
## 228 4.26     Label
## 229 4.28     Label
## 230 4.28     Label
## 231 4.28     Label
## 232 4.28     Label
## 233 4.29     Label
## 234 4.29     Label
## 235 4.29     Label
## 236 4.29     Label
## 237 4.33     Label
## 238 4.33     Label
## 239 4.33     Label
## 240 4.33     Label
## 241 4.38     Label
## 242 4.38     Label
## 243 4.38     Label
## 244 4.38     Label
## 245 4.55     Label
## 246 4.55     Label
## 247 4.55     Label
## 248 4.55     Label
## 249 4.57     Label
## 250 4.57     Label
## 251 4.57     Label
## 252 4.57     Label
## 253 4.58     Label
## 254 4.58     Label
## 255 4.58     Label
## 256 4.58     Label
## 257 4.60     Label
## 258 4.60     Label
## 259 4.60     Label
## 260 4.60     Label
## 261 4.62     Label
## 262 4.62     Label
## 263 4.62     Label
## 264 4.62     Label
## 265 4.64     Label
## 266 4.64     Label
## 267 4.64     Label
## 268 4.64     Label
## 269 4.64     Label
## 270 4.64     Label
## 271 4.64     Label
## 272 4.64     Label
## 273 4.73     Label
## 274 4.73     Label
## 275 4.73     Label
## 276 4.73     Label
## 277 4.82     Label
## 278 4.82     Label
## 279 4.82     Label
## 280 4.82     Label
## 281 4.84     Label
## 282 4.84     Label
## 283 4.84     Label
## 284 4.84     Label
## 285 4.89     Label
## 286 4.89     Label
## 287 4.89     Label
## 288 4.89     Label
## 289 4.89     Label
## 290 4.89     Label
## 291 4.89     Label
## 292 4.89     Label
## 293 4.95     Label
## 294 4.95     Label
## 295 4.95     Label
## 296 4.95     Label
## 297 4.96     Label
## 298 4.96     Label
## 299 4.96     Label
## 300 4.96     Label
## 301 2.01  No Label
## 302 2.01  No Label
## 303 2.01  No Label
## 304 2.01  No Label
## 305 2.03  No Label
## 306 2.03  No Label
## 307 2.03  No Label
## 308 2.03  No Label
## 309 2.07  No Label
## 310 2.07  No Label
## 311 2.07  No Label
## 312 2.07  No Label
## 313 2.25  No Label
## 314 2.25  No Label
## 315 2.25  No Label
## 316 2.25  No Label
## 317 2.50  No Label
## 318 2.50  No Label
## 319 2.50  No Label
## 320 2.50  No Label
## 321 2.59  No Label
## 322 2.59  No Label
## 323 2.59  No Label
## 324 2.59  No Label
## 325 2.71  No Label
## 326 2.71  No Label
## 327 2.71  No Label
## 328 2.71  No Label
## 329 2.88  No Label
## 330 2.88  No Label
## 331 2.88  No Label
## 332 2.88  No Label
## 333 2.90  No Label
## 334 2.90  No Label
## 335 2.90  No Label
## 336 2.90  No Label
## 337 2.93  No Label
## 338 2.93  No Label
## 339 2.93  No Label
## 340 2.93  No Label
## 341 2.99  No Label
## 342 2.99  No Label
## 343 2.99  No Label
## 344 2.99  No Label
## 345 3.02  No Label
## 346 3.02  No Label
## 347 3.02  No Label
## 348 3.02  No Label
## 349 3.02  No Label
## 350 3.02  No Label
## 351 3.02  No Label
## 352 3.02  No Label
## 353 3.06  No Label
## 354 3.06  No Label
## 355 3.06  No Label
## 356 3.06  No Label
## 357 3.06  No Label
## 358 3.06  No Label
## 359 3.06  No Label
## 360 3.06  No Label
## 361 3.18  No Label
## 362 3.18  No Label
## 363 3.18  No Label
## 364 3.18  No Label
## 365 3.27  No Label
## 366 3.27  No Label
## 367 3.27  No Label
## 368 3.27  No Label
## 369 3.27  No Label
## 370 3.27  No Label
## 371 3.27  No Label
## 372 3.27  No Label
## 373 3.33  No Label
## 374 3.33  No Label
## 375 3.33  No Label
## 376 3.33  No Label
## 377 3.41  No Label
## 378 3.41  No Label
## 379 3.41  No Label
## 380 3.41  No Label
## 381 3.41  No Label
## 382 3.45  No Label
## 383 3.45  No Label
## 384 3.45  No Label
## 385 3.45  No Label
## 386 3.50  No Label
## 387 3.50  No Label
## 388 3.50  No Label
## 389 3.50  No Label
## 390 3.54  No Label
## 391 3.54  No Label
## 392 3.54  No Label
## 393 3.54  No Label
## 394 3.71  No Label
## 395 3.71  No Label
## 396 3.71  No Label
## 397 3.71  No Label
## 398 3.76  No Label
## 399 3.76  No Label
## 400 3.76  No Label
## 401 3.76  No Label
## 402 3.82  No Label
## 403 3.82  No Label
## 404 3.82  No Label
## 405 3.83  No Label
## 406 3.83  No Label
## 407 3.83  No Label
## 408 3.83  No Label
## 409 3.93  No Label
## 410 3.93  No Label
## 411 3.94  No Label
## 412 3.94  No Label
## 413 4.02  No Label
## 414 4.02  No Label
## 415 4.02  No Label
## 416 4.02  No Label
## 417 4.02  No Label
## 418 4.02  No Label
## 419 4.02  No Label
## 420 4.02  No Label
## 421 4.07  No Label
## 422 4.07  No Label
## 423 4.07  No Label
## 424 4.07  No Label
## 425 4.09  No Label
## 426 4.09  No Label
## 427 4.09  No Label
## 428 4.09  No Label
## 429 4.25  No Label
## 430 4.25  No Label
## 431 4.25  No Label
## 432 4.25  No Label
## 433 4.32  No Label
## 434 4.32  No Label
## 435 4.32  No Label
## 436 4.32  No Label
## 437 4.37  No Label
## 438 4.37  No Label
## 439 4.37  No Label
## 440 4.37  No Label
## 441 4.39  No Label
## 442 4.39  No Label
## 443 4.39  No Label
## 444 4.39  No Label
## 445 4.41  No Label
## 446 4.41  No Label
## 447 4.41  No Label
## 448 4.41  No Label
## 449 4.41  No Label
## 450 4.41  No Label
## 451 4.41  No Label
## 452 4.41  No Label
## 453 4.42  No Label
## 454 4.42  No Label
## 455 4.42  No Label
## 456 4.42  No Label
## 457 4.44  No Label
## 458 4.44  No Label
## 459 4.44  No Label
## 460 4.44  No Label
## 461 4.47  No Label
## 462 4.47  No Label
## 463 4.47  No Label
## 464 4.47  No Label
## 465 4.47  No Label
## 466 4.47  No Label
## 467 4.47  No Label
## 468 4.47  No Label
## 469 4.52  No Label
## 470 4.52  No Label
## 471 4.52  No Label
## 472 4.52  No Label
## 473 4.55  No Label
## 474 4.55  No Label
## 475 4.55  No Label
## 476 4.55  No Label
## 477 4.58  No Label
## 478 4.58  No Label
## 479 4.58  No Label
## 480 4.58  No Label
## 481 4.61  No Label
## 482 4.61  No Label
## 483 4.61  No Label
## 484 4.61  No Label
## 485 4.61  No Label
## 486 4.61  No Label
## 487 4.61  No Label
## 488 4.61  No Label
## 489 4.75  No Label
## 490 4.75  No Label
## 491 4.75  No Label
## 492 4.75  No Label
## 493 4.76  No Label
## 494 4.76  No Label
## 495 4.76  No Label
## 496 4.76  No Label
## 497 4.79  No Label
## 498 4.79  No Label
## 499 4.79  No Label
## 500 4.79  No Label
## 501 4.82  No Label
## 502 4.82  No Label
## 503 4.82  No Label
## 504 4.82  No Label
## 505 4.82  No Label
## 506 4.82  No Label
## 507 4.82  No Label
## 508 4.82  No Label
## 509 3.50  No Label
## 510 3.50  No Label
## 511 3.50  No Label
## 512 3.50  No Label
## 513 3.24  No Label
## 514 3.24  No Label
## 515 3.24  No Label
## 516 3.24  No Label
## 517 3.94  No Label
## 518 3.94  No Label
## 519 3.94  No Label
## 520 3.94  No Label
## 521 2.72  No Label
## 522 2.72  No Label
## 523 2.72  No Label
## 524 2.72  No Label
## 525 2.31  No Label
## 526 2.31  No Label
## 527 2.31  No Label
## 528 2.31  No Label
## 529 3.14  No Label
## 530 3.14  No Label
## 531 3.14  No Label
## 532 3.14  No Label
## 533 3.72  No Label
## 534 3.72  No Label
## 535 3.72  No Label
## 536 3.72  No Label
## 537 3.10  No Label
## 538 3.10  No Label
## 539 3.10  No Label
## 540 3.10  No Label
## 541 2.34  No Label
## 542 2.34  No Label
## 543 2.34  No Label
## 544 2.34  No Label
## 545 3.67  No Label
## 546 3.67  No Label
## 547 3.67  No Label
## 548 3.66  No Label
## 549 2.58  No Label
## 550 2.58  No Label
## 551 2.58  No Label
## 552 2.58  No Label
## 553 2.55  No Label
## 554 2.55  No Label
## 555 2.55  No Label
## 556 2.55  No Label
## 557 2.43  No Label
## 558 2.43  No Label
## 559 2.43  No Label
## 560 2.43  No Label
## 561 2.70  No Label
## 562 2.70  No Label
## 563 2.70  No Label
## 564 2.70  No Label
## 565 2.76  No Label
## 566 2.76  No Label
## 567 2.76  No Label
## 568 2.76  No Label
## 569 2.84  No Label
## 570 2.84  No Label
## 571 2.84  No Label
## 572 2.84  No Label
## 573 2.46  No Label
## 574 2.46  No Label
## 575 2.46  No Label
## 576 2.46  No Label
## 577 2.37  No Label
## 578 2.37  No Label
## 579 2.37  No Label
## 580 2.37  No Label
## 581 2.83  No Label
## 582 2.83  No Label
## 583 2.83  No Label
## 584 2.83  No Label
## 585 2.69  No Label
## 586 2.69  No Label
## 587 2.69  No Label
## 588 2.69  No Label

You can also use columns’ positions. We could get subid, the first column, by supplying a 1:

select(ps_data, 1)
##      subid
## 1      M22
## 2      M22
## 3      M22
## 4      M22
## 5      T22
## 6      T22
## 7      T22
## 8      T22
## 9      T17
## 10     T17
## 11     T17
## 12     T17
## 13      M3
## 14      M3
## 15      M3
## 16      M3
## 17     T19
## 18     T19
## 19     T19
## 20     T19
## 21     T20
## 22     T20
## 23     T20
## 24     T20
## 25     T21
## 26     T21
## 27     T21
## 28     T21
## 29     M26
## 30     M26
## 31     M26
## 32     M26
## 33     T18
## 34     T18
## 35     T18
## 36     T18
## 37     T12
## 38     T12
## 39     T12
## 40     T12
## 41     T16
## 42     T16
## 43     T16
## 44     T16
## 45      T7
## 46      T7
## 47      T7
## 48      T7
## 49      T9
## 50      T9
## 51      T9
## 52      T9
## 53      T5
## 54      T5
## 55      T5
## 56      T5
## 57     T14
## 58     T14
## 59     T14
## 60     T14
## 61      T2
## 62      T2
## 63      T2
## 64      T2
## 65     T15
## 66     T15
## 67     T15
## 68     T15
## 69     M13
## 70     M13
## 71     M13
## 72     M13
## 73     M12
## 74     M12
## 75     M12
## 76     M12
## 77     T13
## 78     T13
## 79     T13
## 80     T13
## 81      T8
## 82      T8
## 83      T8
## 84      T8
## 85      T1
## 86      T1
## 87      T1
## 88      T1
## 89     M15
## 90     M15
## 91     M15
## 92     M15
## 93     T11
## 94     T11
## 95     T11
## 96     T11
## 97     T10
## 98     T10
## 99     T10
## 100    T10
## 101     T3
## 102     T3
## 103     T3
## 104     T3
## 105     T6
## 106     T6
## 107     T6
## 108     T6
## 109    M32
## 110    M32
## 111    M32
## 112    M32
## 113     M1
## 114     M1
## 115     M1
## 116     M1
## 117    C16
## 118    C16
## 119    C16
## 120    C16
## 121     T4
## 122     T4
## 123     T4
## 124     T4
## 125    C17
## 126    C17
## 127    C17
## 128    C17
## 129     C6
## 130     C6
## 131     C6
## 132     C6
## 133    M10
## 134    M10
## 135    M10
## 136    M10
## 137    M31
## 138    M31
## 139    M31
## 140    M31
## 141     C3
## 142     C3
## 143     C3
## 144     C3
## 145    C10
## 146    C10
## 147    C10
## 148    C10
## 149    M18
## 150    M18
## 151    M18
## 152    M18
## 153    M16
## 154    M16
## 155    M16
## 156    M16
## 157    M23
## 158    M23
## 159    M23
## 160    M23
## 161     C7
## 162     C7
## 163     C7
## 164     C7
## 165    C12
## 166    C12
## 167    C12
## 168    C12
## 169    C15
## 170    C15
## 171    C15
## 172    C15
## 173    M29
## 174    M29
## 175    M29
## 176    M29
## 177    C20
## 178    C20
## 179    C20
## 180    C20
## 181    M11
## 182    M11
## 183    M11
## 184    M11
## 185     C9
## 186     C9
## 187     C9
## 188     C9
## 189    C24
## 190    C24
## 191    C24
## 192    C24
## 193    C22
## 194    C22
## 195    C22
## 196    C22
## 197     C8
## 198     C8
## 199     C8
## 200     C8
## 201     M4
## 202     M4
## 203     M4
## 204     M4
## 205     M6
## 206     M6
## 207     M6
## 208     M6
## 209    C19
## 210    C19
## 211    C19
## 212    C19
## 213     C1
## 214     C1
## 215     C1
## 216     C1
## 217    M19
## 218    M19
## 219    M19
## 220    M19
## 221    C11
## 222    C11
## 223    C11
## 224    C11
## 225     M9
## 226     M9
## 227     M9
## 228     M9
## 229     M2
## 230     M2
## 231     M2
## 232     M2
## 233     C5
## 234     C5
## 235     C5
## 236     C5
## 237    M30
## 238    M30
## 239    M30
## 240    M30
## 241    C13
## 242    C13
## 243    C13
## 244    C13
## 245     C4
## 246     C4
## 247     C4
## 248     C4
## 249    C14
## 250    C14
## 251    C14
## 252    C14
## 253    M17
## 254    M17
## 255    M17
## 256    M17
## 257     C2
## 258     C2
## 259     C2
## 260     C2
## 261    C23
## 262    C23
## 263    C23
## 264    C23
## 265    M20
## 266    M20
## 267    M20
## 268    M20
## 269    M21
## 270    M21
## 271    M21
## 272    M21
## 273    C21
## 274    C21
## 275    C21
## 276    C21
## 277    M24
## 278    M24
## 279    M24
## 280    M24
## 281     M5
## 282     M5
## 283     M5
## 284     M5
## 285     M7
## 286     M7
## 287     M7
## 288     M7
## 289     M8
## 290     M8
## 291     M8
## 292     M8
## 293    C18
## 294    C18
## 295    C18
## 296    C18
## 297    M25
## 298    M25
## 299    M25
## 300    M25
## 301 MSCH47
## 302 MSCH47
## 303 MSCH47
## 304 MSCH47
## 305 MSCH50
## 306 MSCH50
## 307 MSCH50
## 308 MSCH50
## 309 MSCH51
## 310 MSCH51
## 311 MSCH51
## 312 MSCH51
## 313 MSCH44
## 314 MSCH44
## 315 MSCH44
## 316 MSCH44
## 317 MSCH52
## 318 MSCH52
## 319 MSCH52
## 320 MSCH52
## 321 MSCH38
## 322 MSCH38
## 323 MSCH38
## 324 MSCH38
## 325 MSCH43
## 326 MSCH43
## 327 MSCH43
## 328 MSCH43
## 329 MSCH49
## 330 MSCH49
## 331 MSCH49
## 332 MSCH49
## 333 MSCH45
## 334 MSCH45
## 335 MSCH45
## 336 MSCH45
## 337 MSCH42
## 338 MSCH42
## 339 MSCH42
## 340 MSCH42
## 341 MSCH53
## 342 MSCH53
## 343 MSCH53
## 344 MSCH53
## 345  SCH35
## 346  SCH35
## 347  SCH35
## 348  SCH35
## 349 MSCH40
## 350 MSCH40
## 351 MSCH40
## 352 MSCH40
## 353  SCH34
## 354  SCH34
## 355  SCH34
## 356  SCH34
## 357  SCH33
## 358  SCH33
## 359  SCH33
## 360  SCH33
## 361 MSCH41
## 362 MSCH41
## 363 MSCH41
## 364 MSCH41
## 365  SCH37
## 366  SCH37
## 367  SCH37
## 368  SCH37
## 369  SCH32
## 370  SCH32
## 371  SCH32
## 372  SCH32
## 373  SCH36
## 374  SCH36
## 375  SCH36
## 376  SCH36
## 377  SCH11
## 378  SCH12
## 379  SCH12
## 380  SCH12
## 381  SCH12
## 382  SCH18
## 383  SCH18
## 384  SCH18
## 385  SCH18
## 386 MSCH48
## 387 MSCH48
## 388 MSCH48
## 389 MSCH48
## 390  SCH25
## 391  SCH25
## 392  SCH25
## 393  SCH25
## 394  SCH31
## 395  SCH31
## 396  SCH31
## 397  SCH31
## 398 MSCH46
## 399 MSCH46
## 400 MSCH46
## 401 MSCH46
## 402  SCH11
## 403  SCH11
## 404  SCH11
## 405  SCH29
## 406  SCH29
## 407  SCH29
## 408  SCH29
## 409 MSCH39
## 410 MSCH39
## 411 MSCH39
## 412 MSCH39
## 413  SCH28
## 414  SCH28
## 415  SCH28
## 416  SCH28
## 417  SCH22
## 418  SCH22
## 419  SCH22
## 420  SCH22
## 421  SCH24
## 422  SCH24
## 423  SCH24
## 424  SCH24
## 425  SCH27
## 426  SCH27
## 427  SCH27
## 428  SCH27
## 429  SCH17
## 430  SCH17
## 431  SCH17
## 432  SCH17
## 433  SCH10
## 434  SCH10
## 435  SCH10
## 436  SCH10
## 437   SCH9
## 438   SCH9
## 439   SCH9
## 440   SCH9
## 441  SCH20
## 442  SCH20
## 443  SCH20
## 444  SCH20
## 445   SCH6
## 446   SCH6
## 447   SCH6
## 448   SCH6
## 449   SCH7
## 450   SCH7
## 451   SCH7
## 452   SCH7
## 453  SCH15
## 454  SCH15
## 455  SCH15
## 456  SCH15
## 457  SCH30
## 458  SCH30
## 459  SCH30
## 460  SCH30
## 461   SCH3
## 462   SCH3
## 463   SCH3
## 464   SCH3
## 465  SCH26
## 466  SCH26
## 467  SCH26
## 468  SCH26
## 469   SCH8
## 470   SCH8
## 471   SCH8
## 472   SCH8
## 473  SCH16
## 474  SCH16
## 475  SCH16
## 476  SCH16
## 477  SCH14
## 478  SCH14
## 479  SCH14
## 480  SCH14
## 481   SCH2
## 482   SCH2
## 483   SCH2
## 484   SCH2
## 485   SCH5
## 486   SCH5
## 487   SCH5
## 488   SCH5
## 489  SCH13
## 490  SCH13
## 491  SCH13
## 492  SCH13
## 493  SCH21
## 494  SCH21
## 495  SCH21
## 496  SCH21
## 497  SCH19
## 498  SCH19
## 499  SCH19
## 500  SCH19
## 501  SCH23
## 502  SCH23
## 503  SCH23
## 504  SCH23
## 505   SCH1
## 506   SCH1
## 507   SCH1
## 508   SCH1
## 509 MSCH66
## 510 MSCH66
## 511 MSCH66
## 512 MSCH66
## 513 MSCH67
## 514 MSCH67
## 515 MSCH67
## 516 MSCH67
## 517 MSCH68
## 518 MSCH68
## 519 MSCH68
## 520 MSCH68
## 521 MSCH69
## 522 MSCH69
## 523 MSCH69
## 524 MSCH69
## 525 MSCH70
## 526 MSCH70
## 527 MSCH70
## 528 MSCH70
## 529 MSCH71
## 530 MSCH71
## 531 MSCH71
## 532 MSCH71
## 533 MSCH72
## 534 MSCH72
## 535 MSCH72
## 536 MSCH72
## 537 MSCH73
## 538 MSCH73
## 539 MSCH73
## 540 MSCH73
## 541 MSCH74
## 542 MSCH74
## 543 MSCH74
## 544 MSCH74
## 545 MSCH75
## 546 MSCH75
## 547 MSCH75
## 548 MSCH75
## 549 MSCH76
## 550 MSCH76
## 551 MSCH76
## 552 MSCH76
## 553 MSCH77
## 554 MSCH77
## 555 MSCH77
## 556 MSCH77
## 557 MSCH78
## 558 MSCH78
## 559 MSCH78
## 560 MSCH78
## 561 MSCH79
## 562 MSCH79
## 563 MSCH79
## 564 MSCH79
## 565 MSCH80
## 566 MSCH80
## 567 MSCH80
## 568 MSCH80
## 569 MSCH81
## 570 MSCH81
## 571 MSCH81
## 572 MSCH81
## 573 MSCH82
## 574 MSCH82
## 575 MSCH82
## 576 MSCH82
## 577 MSCH83
## 578 MSCH83
## 579 MSCH83
## 580 MSCH83
## 581 MSCH84
## 582 MSCH84
## 583 MSCH84
## 584 MSCH84
## 585 MSCH85
## 586 MSCH85
## 587 MSCH85
## 588 MSCH85

Or, you can say which variable you don’t want by prefacing its name or index with a -. For example, let’s get rid of age.

select(ps_data, -age)
##      subid   item correct condition
## 1      M22  faces       1     Label
## 2      M22 houses       1     Label
## 3      M22  pasta       0     Label
## 4      M22   beds       0     Label
## 5      T22   beds       0     Label
## 6      T22  faces       0     Label
## 7      T22 houses       1     Label
## 8      T22  pasta       1     Label
## 9      T17  pasta       0     Label
## 10     T17  faces       0     Label
## 11     T17 houses       0     Label
## 12     T17   beds       0     Label
## 13      M3  faces       0     Label
## 14      M3 houses       1     Label
## 15      M3  pasta       1     Label
## 16      M3   beds       1     Label
## 17     T19  faces       0     Label
## 18     T19 houses       0     Label
## 19     T19  pasta       1     Label
## 20     T19   beds       1     Label
## 21     T20  faces       1     Label
## 22     T20 houses       1     Label
## 23     T20  pasta       0     Label
## 24     T20   beds       1     Label
## 25     T21  faces       1     Label
## 26     T21 houses       1     Label
## 27     T21  pasta       1     Label
## 28     T21   beds       0     Label
## 29     M26  faces       1     Label
## 30     M26 houses       1     Label
## 31     M26  pasta       0     Label
## 32     M26   beds       1     Label
## 33     T18  faces       1     Label
## 34     T18 houses       0     Label
## 35     T18  pasta       1     Label
## 36     T18   beds       0     Label
## 37     T12   beds       0     Label
## 38     T12  faces       0     Label
## 39     T12 houses       1     Label
## 40     T12  pasta       0     Label
## 41     T16  faces       1     Label
## 42     T16 houses       0     Label
## 43     T16  pasta       1     Label
## 44     T16   beds       1     Label
## 45      T7  faces       1     Label
## 46      T7 houses       0     Label
## 47      T7  pasta       0     Label
## 48      T7   beds       0     Label
## 49      T9 houses       0     Label
## 50      T9  faces       1     Label
## 51      T9  pasta       0     Label
## 52      T9   beds       1     Label
## 53      T5  faces       1     Label
## 54      T5 houses       1     Label
## 55      T5  pasta       0     Label
## 56      T5   beds       1     Label
## 57     T14  faces       1     Label
## 58     T14 houses       1     Label
## 59     T14  pasta       0     Label
## 60     T14   beds       1     Label
## 61      T2 houses       0     Label
## 62      T2  faces       0     Label
## 63      T2  pasta       1     Label
## 64      T2   beds       1     Label
## 65     T15  faces       0     Label
## 66     T15 houses       0     Label
## 67     T15  pasta       1     Label
## 68     T15   beds       0     Label
## 69     M13 houses       0     Label
## 70     M13   beds       1     Label
## 71     M13  faces       1     Label
## 72     M13  pasta       0     Label
## 73     M12  faces       1     Label
## 74     M12 houses       0     Label
## 75     M12  pasta       1     Label
## 76     M12   beds       0     Label
## 77     T13   beds       0     Label
## 78     T13  faces       0     Label
## 79     T13 houses       1     Label
## 80     T13  pasta       1     Label
## 81      T8  faces       1     Label
## 82      T8 houses       0     Label
## 83      T8  pasta       1     Label
## 84      T8   beds       1     Label
## 85      T1  faces       1     Label
## 86      T1 houses       0     Label
## 87      T1  pasta       0     Label
## 88      T1   beds       1     Label
## 89     M15  faces       1     Label
## 90     M15 houses       1     Label
## 91     M15  pasta       1     Label
## 92     M15   beds       1     Label
## 93     T11  faces       1     Label
## 94     T11 houses       0     Label
## 95     T11  pasta       1     Label
## 96     T11   beds       1     Label
## 97     T10  faces       0     Label
## 98     T10 houses       1     Label
## 99     T10  pasta       1     Label
## 100    T10   beds       1     Label
## 101     T3  faces       1     Label
## 102     T3 houses       1     Label
## 103     T3  pasta       1     Label
## 104     T3   beds       1     Label
## 105     T6  faces       1     Label
## 106     T6 houses       1     Label
## 107     T6  pasta       1     Label
## 108     T6   beds       1     Label
## 109    M32   beds       1     Label
## 110    M32  faces       1     Label
## 111    M32 houses       0     Label
## 112    M32  pasta       1     Label
## 113     M1  faces       0     Label
## 114     M1   beds       1     Label
## 115     M1  pasta       0     Label
## 116     M1 houses       0     Label
## 117    C16  faces       0     Label
## 118    C16 houses       0     Label
## 119    C16  pasta       1     Label
## 120    C16   beds       1     Label
## 121     T4  faces       1     Label
## 122     T4 houses       0     Label
## 123     T4  pasta       0     Label
## 124     T4   beds       1     Label
## 125    C17  faces       1     Label
## 126    C17 houses       0     Label
## 127    C17  pasta       1     Label
## 128    C17   beds       0     Label
## 129     C6  faces       0     Label
## 130     C6 houses       1     Label
## 131     C6  pasta       1     Label
## 132     C6   beds       1     Label
## 133    M10  faces       1     Label
## 134    M10 houses       1     Label
## 135    M10   beds       1     Label
## 136    M10  pasta       1     Label
## 137    M31  faces       0     Label
## 138    M31 houses       1     Label
## 139    M31  pasta       1     Label
## 140    M31   beds       1     Label
## 141     C3 houses       0     Label
## 142     C3  pasta       1     Label
## 143     C3   beds       1     Label
## 144     C3  faces       1     Label
## 145    C10  faces       0     Label
## 146    C10 houses       0     Label
## 147    C10  pasta       1     Label
## 148    C10   beds       1     Label
## 149    M18  faces       0     Label
## 150    M18 houses       1     Label
## 151    M18  pasta       1     Label
## 152    M18   beds       1     Label
## 153    M16  faces       0     Label
## 154    M16 houses       0     Label
## 155    M16  pasta       0     Label
## 156    M16   beds       1     Label
## 157    M23  faces       1     Label
## 158    M23 houses       0     Label
## 159    M23  pasta       1     Label
## 160    M23   beds       1     Label
## 161     C7  faces       0     Label
## 162     C7 houses       1     Label
## 163     C7  pasta       0     Label
## 164     C7   beds       0     Label
## 165    C12  faces       1     Label
## 166    C12 houses       0     Label
## 167    C12  pasta       1     Label
## 168    C12   beds       1     Label
## 169    C15  faces       1     Label
## 170    C15 houses       1     Label
## 171    C15  pasta       1     Label
## 172    C15   beds       1     Label
## 173    M29  faces       0     Label
## 174    M29 houses       1     Label
## 175    M29  pasta       1     Label
## 176    M29   beds       1     Label
## 177    C20  faces       1     Label
## 178    C20 houses       1     Label
## 179    C20  pasta       1     Label
## 180    C20   beds       1     Label
## 181    M11  faces       1     Label
## 182    M11 houses       0     Label
## 183    M11  pasta       1     Label
## 184    M11   beds       1     Label
## 185     C9   beds       1     Label
## 186     C9  faces       1     Label
## 187     C9 houses       1     Label
## 188     C9  pasta       1     Label
## 189    C24  faces       1     Label
## 190    C24 houses       0     Label
## 191    C24  pasta       0     Label
## 192    C24   beds       1     Label
## 193    C22  faces       0     Label
## 194    C22 houses       0     Label
## 195    C22  pasta       1     Label
## 196    C22   beds       1     Label
## 197     C8  faces       1     Label
## 198     C8 houses       1     Label
## 199     C8  pasta       1     Label
## 200     C8   beds       1     Label
## 201     M4  faces       1     Label
## 202     M4 houses       1     Label
## 203     M4  pasta       1     Label
## 204     M4   beds       1     Label
## 205     M6  faces       0     Label
## 206     M6 houses       1     Label
## 207     M6  pasta       1     Label
## 208     M6   beds       0     Label
## 209    C19  faces       1     Label
## 210    C19 houses       0     Label
## 211    C19  pasta       0     Label
## 212    C19   beds       1     Label
## 213     C1  faces       1     Label
## 214     C1 houses       1     Label
## 215     C1  pasta       1     Label
## 216     C1   beds       1     Label
## 217    M19   beds       1     Label
## 218    M19  faces       0     Label
## 219    M19 houses       0     Label
## 220    M19  pasta       1     Label
## 221    C11  faces       1     Label
## 222    C11 houses       0     Label
## 223    C11  pasta       1     Label
## 224    C11   beds       1     Label
## 225     M9  faces       1     Label
## 226     M9 houses       1     Label
## 227     M9  pasta       1     Label
## 228     M9   beds       1     Label
## 229     M2  faces       1     Label
## 230     M2 houses       0     Label
## 231     M2  pasta       1     Label
## 232     M2   beds       1     Label
## 233     C5  faces       1     Label
## 234     C5 houses       1     Label
## 235     C5  pasta       1     Label
## 236     C5   beds       1     Label
## 237    M30   beds       1     Label
## 238    M30  faces       1     Label
## 239    M30 houses       0     Label
## 240    M30  pasta       1     Label
## 241    C13  faces       0     Label
## 242    C13 houses       1     Label
## 243    C13  pasta       0     Label
## 244    C13   beds       1     Label
## 245     C4  faces       1     Label
## 246     C4 houses       1     Label
## 247     C4  pasta       1     Label
## 248     C4   beds       1     Label
## 249    C14  faces       1     Label
## 250    C14 houses       1     Label
## 251    C14  pasta       0     Label
## 252    C14   beds       1     Label
## 253    M17  faces       1     Label
## 254    M17 houses       1     Label
## 255    M17  pasta       1     Label
## 256    M17   beds       1     Label
## 257     C2  faces       1     Label
## 258     C2 houses       1     Label
## 259     C2  pasta       1     Label
## 260     C2   beds       1     Label
## 261    C23  faces       0     Label
## 262    C23 houses       1     Label
## 263    C23  pasta       1     Label
## 264    C23   beds       0     Label
## 265    M20  faces       0     Label
## 266    M20 houses       0     Label
## 267    M20  pasta       1     Label
## 268    M20   beds       1     Label
## 269    M21  faces       1     Label
## 270    M21 houses       1     Label
## 271    M21  pasta       1     Label
## 272    M21   beds       1     Label
## 273    C21  faces       1     Label
## 274    C21 houses       0     Label
## 275    C21  pasta       1     Label
## 276    C21   beds       1     Label
## 277    M24  faces       1     Label
## 278    M24 houses       1     Label
## 279    M24  pasta       1     Label
## 280    M24   beds       1     Label
## 281     M5  faces       0     Label
## 282     M5 houses       0     Label
## 283     M5  pasta       0     Label
## 284     M5   beds       1     Label
## 285     M7  faces       1     Label
## 286     M7 houses       1     Label
## 287     M7  pasta       1     Label
## 288     M7   beds       0     Label
## 289     M8  faces       1     Label
## 290     M8 houses       1     Label
## 291     M8  pasta       1     Label
## 292     M8   beds       1     Label
## 293    C18  faces       0     Label
## 294    C18 houses       1     Label
## 295    C18  pasta       1     Label
## 296    C18   beds       1     Label
## 297    M25  faces       1     Label
## 298    M25 houses       1     Label
## 299    M25  pasta       1     Label
## 300    M25   beds       1     Label
## 301 MSCH47  faces       1  No Label
## 302 MSCH47 houses       0  No Label
## 303 MSCH47  pasta       1  No Label
## 304 MSCH47   beds       0  No Label
## 305 MSCH50  faces       0  No Label
## 306 MSCH50 houses       0  No Label
## 307 MSCH50  pasta       0  No Label
## 308 MSCH50   beds       0  No Label
## 309 MSCH51  faces       0  No Label
## 310 MSCH51 houses       0  No Label
## 311 MSCH51  pasta       0  No Label
## 312 MSCH51   beds       0  No Label
## 313 MSCH44  faces       0  No Label
## 314 MSCH44 houses       0  No Label
## 315 MSCH44  pasta       0  No Label
## 316 MSCH44   beds       0  No Label
## 317 MSCH52  faces       0  No Label
## 318 MSCH52 houses       1  No Label
## 319 MSCH52  pasta       0  No Label
## 320 MSCH52   beds       1  No Label
## 321 MSCH38  faces       0  No Label
## 322 MSCH38 houses       0  No Label
## 323 MSCH38  pasta       1  No Label
## 324 MSCH38   beds       0  No Label
## 325 MSCH43  faces       0  No Label
## 326 MSCH43 houses       0  No Label
## 327 MSCH43  pasta       0  No Label
## 328 MSCH43   beds       0  No Label
## 329 MSCH49  faces       0  No Label
## 330 MSCH49 houses       0  No Label
## 331 MSCH49  pasta       0  No Label
## 332 MSCH49   beds       0  No Label
## 333 MSCH45  faces       0  No Label
## 334 MSCH45 houses       0  No Label
## 335 MSCH45  pasta       0  No Label
## 336 MSCH45   beds       1  No Label
## 337 MSCH42  faces       1  No Label
## 338 MSCH42 houses       0  No Label
## 339 MSCH42  pasta       0  No Label
## 340 MSCH42   beds       0  No Label
## 341 MSCH53  faces       1  No Label
## 342 MSCH53 houses       1  No Label
## 343 MSCH53  pasta       0  No Label
## 344 MSCH53   beds       0  No Label
## 345  SCH35  faces       0  No Label
## 346  SCH35 houses       0  No Label
## 347  SCH35  pasta       0  No Label
## 348  SCH35   beds       0  No Label
## 349 MSCH40  faces       0  No Label
## 350 MSCH40 houses       1  No Label
## 351 MSCH40  pasta       0  No Label
## 352 MSCH40   beds       1  No Label
## 353  SCH34  faces       0  No Label
## 354  SCH34 houses       0  No Label
## 355  SCH34  pasta       0  No Label
## 356  SCH34   beds       0  No Label
## 357  SCH33  faces       0  No Label
## 358  SCH33 houses       0  No Label
## 359  SCH33  pasta       0  No Label
## 360  SCH33   beds       0  No Label
## 361 MSCH41  faces       0  No Label
## 362 MSCH41 houses       0  No Label
## 363 MSCH41  pasta       0  No Label
## 364 MSCH41   beds       0  No Label
## 365  SCH37   beds       0  No Label
## 366  SCH37  faces       1  No Label
## 367  SCH37 houses       0  No Label
## 368  SCH37  pasta       1  No Label
## 369  SCH32  faces       1  No Label
## 370  SCH32 houses       0  No Label
## 371  SCH32  pasta       0  No Label
## 372  SCH32   beds       0  No Label
## 373  SCH36   beds       0  No Label
## 374  SCH36  faces       0  No Label
## 375  SCH36 houses       1  No Label
## 376  SCH36  pasta       1  No Label
## 377  SCH11   beds       0  No Label
## 378  SCH12  faces       0  No Label
## 379  SCH12 houses       0  No Label
## 380  SCH12  pasta       0  No Label
## 381  SCH12   beds       0  No Label
## 382  SCH18  faces       0  No Label
## 383  SCH18 houses       0  No Label
## 384  SCH18  pasta       0  No Label
## 385  SCH18   beds       0  No Label
## 386 MSCH48  faces       0  No Label
## 387 MSCH48 houses       1  No Label
## 388 MSCH48  pasta       0  No Label
## 389 MSCH48   beds       0  No Label
## 390  SCH25  faces       0  No Label
## 391  SCH25 houses       1  No Label
## 392  SCH25  pasta       1  No Label
## 393  SCH25   beds       0  No Label
## 394  SCH31  faces       0  No Label
## 395  SCH31 houses       0  No Label
## 396  SCH31  pasta       0  No Label
## 397  SCH31   beds       0  No Label
## 398 MSCH46  faces       0  No Label
## 399 MSCH46 houses       0  No Label
## 400 MSCH46  pasta       1  No Label
## 401 MSCH46   beds       0  No Label
## 402  SCH11  faces       1  No Label
## 403  SCH11 houses       1  No Label
## 404  SCH11  pasta       1  No Label
## 405  SCH29  faces       0  No Label
## 406  SCH29 houses       0  No Label
## 407  SCH29  pasta       0  No Label
## 408  SCH29   beds       0  No Label
## 409 MSCH39   beds       1  No Label
## 410 MSCH39  pasta       0  No Label
## 411 MSCH39 houses       0  No Label
## 412 MSCH39  faces       0  No Label
## 413  SCH28  faces       0  No Label
## 414  SCH28 houses       0  No Label
## 415  SCH28  pasta       0  No Label
## 416  SCH28   beds       0  No Label
## 417  SCH22  faces       0  No Label
## 418  SCH22 houses       0  No Label
## 419  SCH22  pasta       0  No Label
## 420  SCH22   beds       1  No Label
## 421  SCH24  faces       0  No Label
## 422  SCH24 houses       0  No Label
## 423  SCH24  pasta       1  No Label
## 424  SCH24   beds       0  No Label
## 425  SCH27  faces       0  No Label
## 426  SCH27 houses       0  No Label
## 427  SCH27  pasta       1  No Label
## 428  SCH27   beds       0  No Label
## 429  SCH17  faces       0  No Label
## 430  SCH17 houses       0  No Label
## 431  SCH17  pasta       1  No Label
## 432  SCH17   beds       0  No Label
## 433  SCH10  faces       0  No Label
## 434  SCH10 houses       0  No Label
## 435  SCH10  pasta       0  No Label
## 436  SCH10   beds       1  No Label
## 437   SCH9  faces       0  No Label
## 438   SCH9 houses       0  No Label
## 439   SCH9  pasta       0  No Label
## 440   SCH9   beds       0  No Label
## 441  SCH20  faces       0  No Label
## 442  SCH20 houses       0  No Label
## 443  SCH20  pasta       0  No Label
## 444  SCH20   beds       0  No Label
## 445   SCH6  faces       0  No Label
## 446   SCH6 houses       0  No Label
## 447   SCH6  pasta       0  No Label
## 448   SCH6   beds       0  No Label
## 449   SCH7  faces       1  No Label
## 450   SCH7 houses       0  No Label
## 451   SCH7  pasta       0  No Label
## 452   SCH7   beds       0  No Label
## 453  SCH15  faces       1  No Label
## 454  SCH15 houses       0  No Label
## 455  SCH15  pasta       0  No Label
## 456  SCH15   beds       0  No Label
## 457  SCH30  faces       0  No Label
## 458  SCH30 houses       0  No Label
## 459  SCH30  pasta       1  No Label
## 460  SCH30   beds       0  No Label
## 461   SCH3  faces       0  No Label
## 462   SCH3 houses       0  No Label
## 463   SCH3  pasta       0  No Label
## 464   SCH3   beds       0  No Label
## 465  SCH26  faces       0  No Label
## 466  SCH26 houses       0  No Label
## 467  SCH26  pasta       1  No Label
## 468  SCH26   beds       0  No Label
## 469   SCH8  faces       0  No Label
## 470   SCH8 houses       0  No Label
## 471   SCH8  pasta       0  No Label
## 472   SCH8   beds       0  No Label
## 473  SCH16  faces       0  No Label
## 474  SCH16 houses       0  No Label
## 475  SCH16  pasta       0  No Label
## 476  SCH16   beds       1  No Label
## 477  SCH14  faces       0  No Label
## 478  SCH14 houses       0  No Label
## 479  SCH14  pasta       0  No Label
## 480  SCH14   beds       1  No Label
## 481   SCH2  faces       0  No Label
## 482   SCH2 houses       0  No Label
## 483   SCH2  pasta       0  No Label
## 484   SCH2   beds       0  No Label
## 485   SCH5  faces       0  No Label
## 486   SCH5 houses       0  No Label
## 487   SCH5  pasta       0  No Label
## 488   SCH5   beds       0  No Label
## 489  SCH13  faces       0  No Label
## 490  SCH13 houses       0  No Label
## 491  SCH13  pasta       0  No Label
## 492  SCH13   beds       0  No Label
## 493  SCH21  faces       0  No Label
## 494  SCH21 houses       0  No Label
## 495  SCH21  pasta       0  No Label
## 496  SCH21   beds       0  No Label
## 497  SCH19  faces       0  No Label
## 498  SCH19 houses       0  No Label
## 499  SCH19  pasta       0  No Label
## 500  SCH19   beds       1  No Label
## 501  SCH23  faces       0  No Label
## 502  SCH23 houses       0  No Label
## 503  SCH23  pasta       0  No Label
## 504  SCH23   beds       0  No Label
## 505   SCH1  faces       0  No Label
## 506   SCH1 houses       0  No Label
## 507   SCH1  pasta       0  No Label
## 508   SCH1   beds       0  No Label
## 509 MSCH66  faces       0  No Label
## 510 MSCH66 houses       0  No Label
## 511 MSCH66  pasta       1  No Label
## 512 MSCH66   beds       0  No Label
## 513 MSCH67  faces       0  No Label
## 514 MSCH67 houses       1  No Label
## 515 MSCH67  pasta       0  No Label
## 516 MSCH67   beds       1  No Label
## 517 MSCH68  faces       0  No Label
## 518 MSCH68 houses       0  No Label
## 519 MSCH68  pasta       0  No Label
## 520 MSCH68   beds       0  No Label
## 521 MSCH69  faces       0  No Label
## 522 MSCH69 houses       1  No Label
## 523 MSCH69  pasta       1  No Label
## 524 MSCH69   beds       0  No Label
## 525 MSCH70  faces       0  No Label
## 526 MSCH70 houses       0  No Label
## 527 MSCH70  pasta       0  No Label
## 528 MSCH70   beds       1  No Label
## 529 MSCH71  faces       1  No Label
## 530 MSCH71 houses       1  No Label
## 531 MSCH71  pasta       1  No Label
## 532 MSCH71   beds       0  No Label
## 533 MSCH72  faces       1  No Label
## 534 MSCH72 houses       1  No Label
## 535 MSCH72  pasta       0  No Label
## 536 MSCH72   beds       0  No Label
## 537 MSCH73  faces       0  No Label
## 538 MSCH73 houses       0  No Label
## 539 MSCH73  pasta       0  No Label
## 540 MSCH73   beds       0  No Label
## 541 MSCH74  faces       1  No Label
## 542 MSCH74 houses       0  No Label
## 543 MSCH74  pasta       0  No Label
## 544 MSCH74   beds       1  No Label
## 545 MSCH75  faces       0  No Label
## 546 MSCH75 houses       0  No Label
## 547 MSCH75  pasta       0  No Label
## 548 MSCH75   beds       0  No Label
## 549 MSCH76  faces       0  No Label
## 550 MSCH76 houses       0  No Label
## 551 MSCH76  pasta       0  No Label
## 552 MSCH76   beds       0  No Label
## 553 MSCH77  faces       0  No Label
## 554 MSCH77 houses       0  No Label
## 555 MSCH77  pasta       0  No Label
## 556 MSCH77   beds       1  No Label
## 557 MSCH78  faces       0  No Label
## 558 MSCH78 houses       0  No Label
## 559 MSCH78  pasta       0  No Label
## 560 MSCH78   beds       1  No Label
## 561 MSCH79  faces       0  No Label
## 562 MSCH79 houses       1  No Label
## 563 MSCH79  pasta       0  No Label
## 564 MSCH79   beds       1  No Label
## 565 MSCH80  faces       0  No Label
## 566 MSCH80 houses       0  No Label
## 567 MSCH80  pasta       0  No Label
## 568 MSCH80   beds       0  No Label
## 569 MSCH81  faces       1  No Label
## 570 MSCH81 houses       0  No Label
## 571 MSCH81  pasta       0  No Label
## 572 MSCH81   beds       0  No Label
## 573 MSCH82  faces       1  No Label
## 574 MSCH82 houses       0  No Label
## 575 MSCH82  pasta       1  No Label
## 576 MSCH82   beds       0  No Label
## 577 MSCH83  faces       0  No Label
## 578 MSCH83 houses       0  No Label
## 579 MSCH83  pasta       1  No Label
## 580 MSCH83   beds       0  No Label
## 581 MSCH84  faces       0  No Label
## 582 MSCH84 houses       0  No Label
## 583 MSCH84  pasta       1  No Label
## 584 MSCH84   beds       0  No Label
## 585 MSCH85  faces       0  No Label
## 586 MSCH85 houses       0  No Label
## 587 MSCH85  pasta       0  No Label
## 588 MSCH85   beds       0  No Label

You could also get rid of by referencing its index:

select(ps_data, -5)
##      subid   item correct  age
## 1      M22  faces       1 2.00
## 2      M22 houses       1 2.00
## 3      M22  pasta       0 2.00
## 4      M22   beds       0 2.00
## 5      T22   beds       0 2.13
## 6      T22  faces       0 2.13
## 7      T22 houses       1 2.13
## 8      T22  pasta       1 2.13
## 9      T17  pasta       0 2.32
## 10     T17  faces       0 2.32
## 11     T17 houses       0 2.32
## 12     T17   beds       0 2.32
## 13      M3  faces       0 2.38
## 14      M3 houses       1 2.38
## 15      M3  pasta       1 2.38
## 16      M3   beds       1 2.38
## 17     T19  faces       0 2.47
## 18     T19 houses       0 2.47
## 19     T19  pasta       1 2.47
## 20     T19   beds       1 2.47
## 21     T20  faces       1 2.50
## 22     T20 houses       1 2.50
## 23     T20  pasta       0 2.50
## 24     T20   beds       1 2.50
## 25     T21  faces       1 2.58
## 26     T21 houses       1 2.58
## 27     T21  pasta       1 2.58
## 28     T21   beds       0 2.58
## 29     M26  faces       1 2.59
## 30     M26 houses       1 2.59
## 31     M26  pasta       0 2.59
## 32     M26   beds       1 2.59
## 33     T18  faces       1 2.61
## 34     T18 houses       0 2.61
## 35     T18  pasta       1 2.61
## 36     T18   beds       0 2.61
## 37     T12   beds       0 2.72
## 38     T12  faces       0 2.72
## 39     T12 houses       1 2.72
## 40     T12  pasta       0 2.72
## 41     T16  faces       1 2.73
## 42     T16 houses       0 2.73
## 43     T16  pasta       1 2.73
## 44     T16   beds       1 2.73
## 45      T7  faces       1 2.74
## 46      T7 houses       0 2.74
## 47      T7  pasta       0 2.74
## 48      T7   beds       0 2.74
## 49      T9 houses       0 2.79
## 50      T9  faces       1 2.79
## 51      T9  pasta       0 2.79
## 52      T9   beds       1 2.79
## 53      T5  faces       1 2.80
## 54      T5 houses       1 2.80
## 55      T5  pasta       0 2.80
## 56      T5   beds       1 2.80
## 57     T14  faces       1 2.83
## 58     T14 houses       1 2.83
## 59     T14  pasta       0 2.83
## 60     T14   beds       1 2.83
## 61      T2 houses       0 2.83
## 62      T2  faces       0 2.83
## 63      T2  pasta       1 2.83
## 64      T2   beds       1 2.83
## 65     T15  faces       0 2.85
## 66     T15 houses       0 2.85
## 67     T15  pasta       1 2.85
## 68     T15   beds       0 2.85
## 69     M13 houses       0 2.88
## 70     M13   beds       1 2.88
## 71     M13  faces       1 2.88
## 72     M13  pasta       0 2.88
## 73     M12  faces       1 2.88
## 74     M12 houses       0 2.88
## 75     M12  pasta       1 2.88
## 76     M12   beds       0 2.88
## 77     T13   beds       0 2.89
## 78     T13  faces       0 2.89
## 79     T13 houses       1 2.89
## 80     T13  pasta       1 2.89
## 81      T8  faces       1 2.91
## 82      T8 houses       0 2.91
## 83      T8  pasta       1 2.91
## 84      T8   beds       1 2.91
## 85      T1  faces       1 2.95
## 86      T1 houses       0 2.95
## 87      T1  pasta       0 2.95
## 88      T1   beds       1 2.95
## 89     M15  faces       1 2.98
## 90     M15 houses       1 2.98
## 91     M15  pasta       1 2.98
## 92     M15   beds       1 2.98
## 93     T11  faces       1 2.99
## 94     T11 houses       0 2.99
## 95     T11  pasta       1 2.99
## 96     T11   beds       1 2.99
## 97     T10  faces       0 3.00
## 98     T10 houses       1 3.00
## 99     T10  pasta       1 3.00
## 100    T10   beds       1 3.00
## 101     T3  faces       1 3.09
## 102     T3 houses       1 3.09
## 103     T3  pasta       1 3.09
## 104     T3   beds       1 3.09
## 105     T6  faces       1 3.10
## 106     T6 houses       1 3.10
## 107     T6  pasta       1 3.10
## 108     T6   beds       1 3.10
## 109    M32   beds       1 3.19
## 110    M32  faces       1 3.19
## 111    M32 houses       0 3.19
## 112    M32  pasta       1 3.19
## 113     M1  faces       0 3.20
## 114     M1   beds       1 3.20
## 115     M1  pasta       0 3.20
## 116     M1 houses       0 3.20
## 117    C16  faces       0 3.22
## 118    C16 houses       0 3.22
## 119    C16  pasta       1 3.22
## 120    C16   beds       1 3.22
## 121     T4  faces       1 3.24
## 122     T4 houses       0 3.24
## 123     T4  pasta       0 3.24
## 124     T4   beds       1 3.24
## 125    C17  faces       1 3.25
## 126    C17 houses       0 3.25
## 127    C17  pasta       1 3.25
## 128    C17   beds       0 3.25
## 129     C6  faces       0 3.26
## 130     C6 houses       1 3.26
## 131     C6  pasta       1 3.26
## 132     C6   beds       1 3.26
## 133    M10  faces       1 3.28
## 134    M10 houses       1 3.28
## 135    M10   beds       1 3.28
## 136    M10  pasta       1 3.28
## 137    M31  faces       0 3.30
## 138    M31 houses       1 3.30
## 139    M31  pasta       1 3.30
## 140    M31   beds       1 3.30
## 141     C3 houses       0 3.46
## 142     C3  pasta       1 3.46
## 143     C3   beds       1 3.46
## 144     C3  faces       1 3.46
## 145    C10  faces       0 3.46
## 146    C10 houses       0 3.46
## 147    C10  pasta       1 3.46
## 148    C10   beds       1 3.46
## 149    M18  faces       0 3.46
## 150    M18 houses       1 3.46
## 151    M18  pasta       1 3.46
## 152    M18   beds       1 3.46
## 153    M16  faces       0 3.50
## 154    M16 houses       0 3.50
## 155    M16  pasta       0 3.50
## 156    M16   beds       1 3.50
## 157    M23  faces       1 3.52
## 158    M23 houses       0 3.52
## 159    M23  pasta       1 3.52
## 160    M23   beds       1 3.52
## 161     C7  faces       0 3.55
## 162     C7 houses       1 3.55
## 163     C7  pasta       0 3.55
## 164     C7   beds       0 3.55
## 165    C12  faces       1 3.56
## 166    C12 houses       0 3.56
## 167    C12  pasta       1 3.56
## 168    C12   beds       1 3.56
## 169    C15  faces       1 3.59
## 170    C15 houses       1 3.59
## 171    C15  pasta       1 3.59
## 172    C15   beds       1 3.59
## 173    M29  faces       0 3.72
## 174    M29 houses       1 3.72
## 175    M29  pasta       1 3.72
## 176    M29   beds       1 3.72
## 177    C20  faces       1 3.75
## 178    C20 houses       1 3.75
## 179    C20  pasta       1 3.75
## 180    C20   beds       1 3.75
## 181    M11  faces       1 3.82
## 182    M11 houses       0 3.82
## 183    M11  pasta       1 3.82
## 184    M11   beds       1 3.82
## 185     C9   beds       1 3.82
## 186     C9  faces       1 3.82
## 187     C9 houses       1 3.82
## 188     C9  pasta       1 3.82
## 189    C24  faces       1 3.85
## 190    C24 houses       0 3.85
## 191    C24  pasta       0 3.85
## 192    C24   beds       1 3.85
## 193    C22  faces       0 3.92
## 194    C22 houses       0 3.92
## 195    C22  pasta       1 3.92
## 196    C22   beds       1 3.92
## 197     C8  faces       1 3.92
## 198     C8 houses       1 3.92
## 199     C8  pasta       1 3.92
## 200     C8   beds       1 3.92
## 201     M4  faces       1 3.96
## 202     M4 houses       1 3.96
## 203     M4  pasta       1 3.96
## 204     M4   beds       1 3.96
## 205     M6  faces       0 4.50
## 206     M6 houses       1 4.50
## 207     M6  pasta       1 4.50
## 208     M6   beds       0 4.50
## 209    C19  faces       1 4.14
## 210    C19 houses       0 4.14
## 211    C19  pasta       0 4.14
## 212    C19   beds       1 4.14
## 213     C1  faces       1 4.16
## 214     C1 houses       1 4.16
## 215     C1  pasta       1 4.16
## 216     C1   beds       1 4.16
## 217    M19   beds       1 4.16
## 218    M19  faces       0 4.16
## 219    M19 houses       0 4.16
## 220    M19  pasta       1 4.16
## 221    C11  faces       1 4.22
## 222    C11 houses       0 4.22
## 223    C11  pasta       1 4.22
## 224    C11   beds       1 4.22
## 225     M9  faces       1 4.26
## 226     M9 houses       1 4.26
## 227     M9  pasta       1 4.26
## 228     M9   beds       1 4.26
## 229     M2  faces       1 4.28
## 230     M2 houses       0 4.28
## 231     M2  pasta       1 4.28
## 232     M2   beds       1 4.28
## 233     C5  faces       1 4.29
## 234     C5 houses       1 4.29
## 235     C5  pasta       1 4.29
## 236     C5   beds       1 4.29
## 237    M30   beds       1 4.33
## 238    M30  faces       1 4.33
## 239    M30 houses       0 4.33
## 240    M30  pasta       1 4.33
## 241    C13  faces       0 4.38
## 242    C13 houses       1 4.38
## 243    C13  pasta       0 4.38
## 244    C13   beds       1 4.38
## 245     C4  faces       1 4.55
## 246     C4 houses       1 4.55
## 247     C4  pasta       1 4.55
## 248     C4   beds       1 4.55
## 249    C14  faces       1 4.57
## 250    C14 houses       1 4.57
## 251    C14  pasta       0 4.57
## 252    C14   beds       1 4.57
## 253    M17  faces       1 4.58
## 254    M17 houses       1 4.58
## 255    M17  pasta       1 4.58
## 256    M17   beds       1 4.58
## 257     C2  faces       1 4.60
## 258     C2 houses       1 4.60
## 259     C2  pasta       1 4.60
## 260     C2   beds       1 4.60
## 261    C23  faces       0 4.62
## 262    C23 houses       1 4.62
## 263    C23  pasta       1 4.62
## 264    C23   beds       0 4.62
## 265    M20  faces       0 4.64
## 266    M20 houses       0 4.64
## 267    M20  pasta       1 4.64
## 268    M20   beds       1 4.64
## 269    M21  faces       1 4.64
## 270    M21 houses       1 4.64
## 271    M21  pasta       1 4.64
## 272    M21   beds       1 4.64
## 273    C21  faces       1 4.73
## 274    C21 houses       0 4.73
## 275    C21  pasta       1 4.73
## 276    C21   beds       1 4.73
## 277    M24  faces       1 4.82
## 278    M24 houses       1 4.82
## 279    M24  pasta       1 4.82
## 280    M24   beds       1 4.82
## 281     M5  faces       0 4.84
## 282     M5 houses       0 4.84
## 283     M5  pasta       0 4.84
## 284     M5   beds       1 4.84
## 285     M7  faces       1 4.89
## 286     M7 houses       1 4.89
## 287     M7  pasta       1 4.89
## 288     M7   beds       0 4.89
## 289     M8  faces       1 4.89
## 290     M8 houses       1 4.89
## 291     M8  pasta       1 4.89
## 292     M8   beds       1 4.89
## 293    C18  faces       0 4.95
## 294    C18 houses       1 4.95
## 295    C18  pasta       1 4.95
## 296    C18   beds       1 4.95
## 297    M25  faces       1 4.96
## 298    M25 houses       1 4.96
## 299    M25  pasta       1 4.96
## 300    M25   beds       1 4.96
## 301 MSCH47  faces       1 2.01
## 302 MSCH47 houses       0 2.01
## 303 MSCH47  pasta       1 2.01
## 304 MSCH47   beds       0 2.01
## 305 MSCH50  faces       0 2.03
## 306 MSCH50 houses       0 2.03
## 307 MSCH50  pasta       0 2.03
## 308 MSCH50   beds       0 2.03
## 309 MSCH51  faces       0 2.07
## 310 MSCH51 houses       0 2.07
## 311 MSCH51  pasta       0 2.07
## 312 MSCH51   beds       0 2.07
## 313 MSCH44  faces       0 2.25
## 314 MSCH44 houses       0 2.25
## 315 MSCH44  pasta       0 2.25
## 316 MSCH44   beds       0 2.25
## 317 MSCH52  faces       0 2.50
## 318 MSCH52 houses       1 2.50
## 319 MSCH52  pasta       0 2.50
## 320 MSCH52   beds       1 2.50
## 321 MSCH38  faces       0 2.59
## 322 MSCH38 houses       0 2.59
## 323 MSCH38  pasta       1 2.59
## 324 MSCH38   beds       0 2.59
## 325 MSCH43  faces       0 2.71
## 326 MSCH43 houses       0 2.71
## 327 MSCH43  pasta       0 2.71
## 328 MSCH43   beds       0 2.71
## 329 MSCH49  faces       0 2.88
## 330 MSCH49 houses       0 2.88
## 331 MSCH49  pasta       0 2.88
## 332 MSCH49   beds       0 2.88
## 333 MSCH45  faces       0 2.90
## 334 MSCH45 houses       0 2.90
## 335 MSCH45  pasta       0 2.90
## 336 MSCH45   beds       1 2.90
## 337 MSCH42  faces       1 2.93
## 338 MSCH42 houses       0 2.93
## 339 MSCH42  pasta       0 2.93
## 340 MSCH42   beds       0 2.93
## 341 MSCH53  faces       1 2.99
## 342 MSCH53 houses       1 2.99
## 343 MSCH53  pasta       0 2.99
## 344 MSCH53   beds       0 2.99
## 345  SCH35  faces       0 3.02
## 346  SCH35 houses       0 3.02
## 347  SCH35  pasta       0 3.02
## 348  SCH35   beds       0 3.02
## 349 MSCH40  faces       0 3.02
## 350 MSCH40 houses       1 3.02
## 351 MSCH40  pasta       0 3.02
## 352 MSCH40   beds       1 3.02
## 353  SCH34  faces       0 3.06
## 354  SCH34 houses       0 3.06
## 355  SCH34  pasta       0 3.06
## 356  SCH34   beds       0 3.06
## 357  SCH33  faces       0 3.06
## 358  SCH33 houses       0 3.06
## 359  SCH33  pasta       0 3.06
## 360  SCH33   beds       0 3.06
## 361 MSCH41  faces       0 3.18
## 362 MSCH41 houses       0 3.18
## 363 MSCH41  pasta       0 3.18
## 364 MSCH41   beds       0 3.18
## 365  SCH37   beds       0 3.27
## 366  SCH37  faces       1 3.27
## 367  SCH37 houses       0 3.27
## 368  SCH37  pasta       1 3.27
## 369  SCH32  faces       1 3.27
## 370  SCH32 houses       0 3.27
## 371  SCH32  pasta       0 3.27
## 372  SCH32   beds       0 3.27
## 373  SCH36   beds       0 3.33
## 374  SCH36  faces       0 3.33
## 375  SCH36 houses       1 3.33
## 376  SCH36  pasta       1 3.33
## 377  SCH11   beds       0 3.41
## 378  SCH12  faces       0 3.41
## 379  SCH12 houses       0 3.41
## 380  SCH12  pasta       0 3.41
## 381  SCH12   beds       0 3.41
## 382  SCH18  faces       0 3.45
## 383  SCH18 houses       0 3.45
## 384  SCH18  pasta       0 3.45
## 385  SCH18   beds       0 3.45
## 386 MSCH48  faces       0 3.50
## 387 MSCH48 houses       1 3.50
## 388 MSCH48  pasta       0 3.50
## 389 MSCH48   beds       0 3.50
## 390  SCH25  faces       0 3.54
## 391  SCH25 houses       1 3.54
## 392  SCH25  pasta       1 3.54
## 393  SCH25   beds       0 3.54
## 394  SCH31  faces       0 3.71
## 395  SCH31 houses       0 3.71
## 396  SCH31  pasta       0 3.71
## 397  SCH31   beds       0 3.71
## 398 MSCH46  faces       0 3.76
## 399 MSCH46 houses       0 3.76
## 400 MSCH46  pasta       1 3.76
## 401 MSCH46   beds       0 3.76
## 402  SCH11  faces       1 3.82
## 403  SCH11 houses       1 3.82
## 404  SCH11  pasta       1 3.82
## 405  SCH29  faces       0 3.83
## 406  SCH29 houses       0 3.83
## 407  SCH29  pasta       0 3.83
## 408  SCH29   beds       0 3.83
## 409 MSCH39   beds       1 3.93
## 410 MSCH39  pasta       0 3.93
## 411 MSCH39 houses       0 3.94
## 412 MSCH39  faces       0 3.94
## 413  SCH28  faces       0 4.02
## 414  SCH28 houses       0 4.02
## 415  SCH28  pasta       0 4.02
## 416  SCH28   beds       0 4.02
## 417  SCH22  faces       0 4.02
## 418  SCH22 houses       0 4.02
## 419  SCH22  pasta       0 4.02
## 420  SCH22   beds       1 4.02
## 421  SCH24  faces       0 4.07
## 422  SCH24 houses       0 4.07
## 423  SCH24  pasta       1 4.07
## 424  SCH24   beds       0 4.07
## 425  SCH27  faces       0 4.09
## 426  SCH27 houses       0 4.09
## 427  SCH27  pasta       1 4.09
## 428  SCH27   beds       0 4.09
## 429  SCH17  faces       0 4.25
## 430  SCH17 houses       0 4.25
## 431  SCH17  pasta       1 4.25
## 432  SCH17   beds       0 4.25
## 433  SCH10  faces       0 4.32
## 434  SCH10 houses       0 4.32
## 435  SCH10  pasta       0 4.32
## 436  SCH10   beds       1 4.32
## 437   SCH9  faces       0 4.37
## 438   SCH9 houses       0 4.37
## 439   SCH9  pasta       0 4.37
## 440   SCH9   beds       0 4.37
## 441  SCH20  faces       0 4.39
## 442  SCH20 houses       0 4.39
## 443  SCH20  pasta       0 4.39
## 444  SCH20   beds       0 4.39
## 445   SCH6  faces       0 4.41
## 446   SCH6 houses       0 4.41
## 447   SCH6  pasta       0 4.41
## 448   SCH6   beds       0 4.41
## 449   SCH7  faces       1 4.41
## 450   SCH7 houses       0 4.41
## 451   SCH7  pasta       0 4.41
## 452   SCH7   beds       0 4.41
## 453  SCH15  faces       1 4.42
## 454  SCH15 houses       0 4.42
## 455  SCH15  pasta       0 4.42
## 456  SCH15   beds       0 4.42
## 457  SCH30  faces       0 4.44
## 458  SCH30 houses       0 4.44
## 459  SCH30  pasta       1 4.44
## 460  SCH30   beds       0 4.44
## 461   SCH3  faces       0 4.47
## 462   SCH3 houses       0 4.47
## 463   SCH3  pasta       0 4.47
## 464   SCH3   beds       0 4.47
## 465  SCH26  faces       0 4.47
## 466  SCH26 houses       0 4.47
## 467  SCH26  pasta       1 4.47
## 468  SCH26   beds       0 4.47
## 469   SCH8  faces       0 4.52
## 470   SCH8 houses       0 4.52
## 471   SCH8  pasta       0 4.52
## 472   SCH8   beds       0 4.52
## 473  SCH16  faces       0 4.55
## 474  SCH16 houses       0 4.55
## 475  SCH16  pasta       0 4.55
## 476  SCH16   beds       1 4.55
## 477  SCH14  faces       0 4.58
## 478  SCH14 houses       0 4.58
## 479  SCH14  pasta       0 4.58
## 480  SCH14   beds       1 4.58
## 481   SCH2  faces       0 4.61
## 482   SCH2 houses       0 4.61
## 483   SCH2  pasta       0 4.61
## 484   SCH2   beds       0 4.61
## 485   SCH5  faces       0 4.61
## 486   SCH5 houses       0 4.61
## 487   SCH5  pasta       0 4.61
## 488   SCH5   beds       0 4.61
## 489  SCH13  faces       0 4.75
## 490  SCH13 houses       0 4.75
## 491  SCH13  pasta       0 4.75
## 492  SCH13   beds       0 4.75
## 493  SCH21  faces       0 4.76
## 494  SCH21 houses       0 4.76
## 495  SCH21  pasta       0 4.76
## 496  SCH21   beds       0 4.76
## 497  SCH19  faces       0 4.79
## 498  SCH19 houses       0 4.79
## 499  SCH19  pasta       0 4.79
## 500  SCH19   beds       1 4.79
## 501  SCH23  faces       0 4.82
## 502  SCH23 houses       0 4.82
## 503  SCH23  pasta       0 4.82
## 504  SCH23   beds       0 4.82
## 505   SCH1  faces       0 4.82
## 506   SCH1 houses       0 4.82
## 507   SCH1  pasta       0 4.82
## 508   SCH1   beds       0 4.82
## 509 MSCH66  faces       0 3.50
## 510 MSCH66 houses       0 3.50
## 511 MSCH66  pasta       1 3.50
## 512 MSCH66   beds       0 3.50
## 513 MSCH67  faces       0 3.24
## 514 MSCH67 houses       1 3.24
## 515 MSCH67  pasta       0 3.24
## 516 MSCH67   beds       1 3.24
## 517 MSCH68  faces       0 3.94
## 518 MSCH68 houses       0 3.94
## 519 MSCH68  pasta       0 3.94
## 520 MSCH68   beds       0 3.94
## 521 MSCH69  faces       0 2.72
## 522 MSCH69 houses       1 2.72
## 523 MSCH69  pasta       1 2.72
## 524 MSCH69   beds       0 2.72
## 525 MSCH70  faces       0 2.31
## 526 MSCH70 houses       0 2.31
## 527 MSCH70  pasta       0 2.31
## 528 MSCH70   beds       1 2.31
## 529 MSCH71  faces       1 3.14
## 530 MSCH71 houses       1 3.14
## 531 MSCH71  pasta       1 3.14
## 532 MSCH71   beds       0 3.14
## 533 MSCH72  faces       1 3.72
## 534 MSCH72 houses       1 3.72
## 535 MSCH72  pasta       0 3.72
## 536 MSCH72   beds       0 3.72
## 537 MSCH73  faces       0 3.10
## 538 MSCH73 houses       0 3.10
## 539 MSCH73  pasta       0 3.10
## 540 MSCH73   beds       0 3.10
## 541 MSCH74  faces       1 2.34
## 542 MSCH74 houses       0 2.34
## 543 MSCH74  pasta       0 2.34
## 544 MSCH74   beds       1 2.34
## 545 MSCH75  faces       0 3.67
## 546 MSCH75 houses       0 3.67
## 547 MSCH75  pasta       0 3.67
## 548 MSCH75   beds       0 3.66
## 549 MSCH76  faces       0 2.58
## 550 MSCH76 houses       0 2.58
## 551 MSCH76  pasta       0 2.58
## 552 MSCH76   beds       0 2.58
## 553 MSCH77  faces       0 2.55
## 554 MSCH77 houses       0 2.55
## 555 MSCH77  pasta       0 2.55
## 556 MSCH77   beds       1 2.55
## 557 MSCH78  faces       0 2.43
## 558 MSCH78 houses       0 2.43
## 559 MSCH78  pasta       0 2.43
## 560 MSCH78   beds       1 2.43
## 561 MSCH79  faces       0 2.70
## 562 MSCH79 houses       1 2.70
## 563 MSCH79  pasta       0 2.70
## 564 MSCH79   beds       1 2.70
## 565 MSCH80  faces       0 2.76
## 566 MSCH80 houses       0 2.76
## 567 MSCH80  pasta       0 2.76
## 568 MSCH80   beds       0 2.76
## 569 MSCH81  faces       1 2.84
## 570 MSCH81 houses       0 2.84
## 571 MSCH81  pasta       0 2.84
## 572 MSCH81   beds       0 2.84
## 573 MSCH82  faces       1 2.46
## 574 MSCH82 houses       0 2.46
## 575 MSCH82  pasta       1 2.46
## 576 MSCH82   beds       0 2.46
## 577 MSCH83  faces       0 2.37
## 578 MSCH83 houses       0 2.37
## 579 MSCH83  pasta       1 2.37
## 580 MSCH83   beds       0 2.37
## 581 MSCH84  faces       0 2.83
## 582 MSCH84 houses       0 2.83
## 583 MSCH84  pasta       1 2.83
## 584 MSCH84   beds       0 2.83
## 585 MSCH85  faces       0 2.69
## 586 MSCH85 houses       0 2.69
## 587 MSCH85  pasta       0 2.69
## 588 MSCH85   beds       0 2.69

You can also use : to select or de-select a range of variables. This can be done with reference to their numerical index:

# select first three:
select(ps_data, 1:3)
##      subid   item correct
## 1      M22  faces       1
## 2      M22 houses       1
## 3      M22  pasta       0
## 4      M22   beds       0
## 5      T22   beds       0
## 6      T22  faces       0
## 7      T22 houses       1
## 8      T22  pasta       1
## 9      T17  pasta       0
## 10     T17  faces       0
## 11     T17 houses       0
## 12     T17   beds       0
## 13      M3  faces       0
## 14      M3 houses       1
## 15      M3  pasta       1
## 16      M3   beds       1
## 17     T19  faces       0
## 18     T19 houses       0
## 19     T19  pasta       1
## 20     T19   beds       1
## 21     T20  faces       1
## 22     T20 houses       1
## 23     T20  pasta       0
## 24     T20   beds       1
## 25     T21  faces       1
## 26     T21 houses       1
## 27     T21  pasta       1
## 28     T21   beds       0
## 29     M26  faces       1
## 30     M26 houses       1
## 31     M26  pasta       0
## 32     M26   beds       1
## 33     T18  faces       1
## 34     T18 houses       0
## 35     T18  pasta       1
## 36     T18   beds       0
## 37     T12   beds       0
## 38     T12  faces       0
## 39     T12 houses       1
## 40     T12  pasta       0
## 41     T16  faces       1
## 42     T16 houses       0
## 43     T16  pasta       1
## 44     T16   beds       1
## 45      T7  faces       1
## 46      T7 houses       0
## 47      T7  pasta       0
## 48      T7   beds       0
## 49      T9 houses       0
## 50      T9  faces       1
## 51      T9  pasta       0
## 52      T9   beds       1
## 53      T5  faces       1
## 54      T5 houses       1
## 55      T5  pasta       0
## 56      T5   beds       1
## 57     T14  faces       1
## 58     T14 houses       1
## 59     T14  pasta       0
## 60     T14   beds       1
## 61      T2 houses       0
## 62      T2  faces       0
## 63      T2  pasta       1
## 64      T2   beds       1
## 65     T15  faces       0
## 66     T15 houses       0
## 67     T15  pasta       1
## 68     T15   beds       0
## 69     M13 houses       0
## 70     M13   beds       1
## 71     M13  faces       1
## 72     M13  pasta       0
## 73     M12  faces       1
## 74     M12 houses       0
## 75     M12  pasta       1
## 76     M12   beds       0
## 77     T13   beds       0
## 78     T13  faces       0
## 79     T13 houses       1
## 80     T13  pasta       1
## 81      T8  faces       1
## 82      T8 houses       0
## 83      T8  pasta       1
## 84      T8   beds       1
## 85      T1  faces       1
## 86      T1 houses       0
## 87      T1  pasta       0
## 88      T1   beds       1
## 89     M15  faces       1
## 90     M15 houses       1
## 91     M15  pasta       1
## 92     M15   beds       1
## 93     T11  faces       1
## 94     T11 houses       0
## 95     T11  pasta       1
## 96     T11   beds       1
## 97     T10  faces       0
## 98     T10 houses       1
## 99     T10  pasta       1
## 100    T10   beds       1
## 101     T3  faces       1
## 102     T3 houses       1
## 103     T3  pasta       1
## 104     T3   beds       1
## 105     T6  faces       1
## 106     T6 houses       1
## 107     T6  pasta       1
## 108     T6   beds       1
## 109    M32   beds       1
## 110    M32  faces       1
## 111    M32 houses       0
## 112    M32  pasta       1
## 113     M1  faces       0
## 114     M1   beds       1
## 115     M1  pasta       0
## 116     M1 houses       0
## 117    C16  faces       0
## 118    C16 houses       0
## 119    C16  pasta       1
## 120    C16   beds       1
## 121     T4  faces       1
## 122     T4 houses       0
## 123     T4  pasta       0
## 124     T4   beds       1
## 125    C17  faces       1
## 126    C17 houses       0
## 127    C17  pasta       1
## 128    C17   beds       0
## 129     C6  faces       0
## 130     C6 houses       1
## 131     C6  pasta       1
## 132     C6   beds       1
## 133    M10  faces       1
## 134    M10 houses       1
## 135    M10   beds       1
## 136    M10  pasta       1
## 137    M31  faces       0
## 138    M31 houses       1
## 139    M31  pasta       1
## 140    M31   beds       1
## 141     C3 houses       0
## 142     C3  pasta       1
## 143     C3   beds       1
## 144     C3  faces       1
## 145    C10  faces       0
## 146    C10 houses       0
## 147    C10  pasta       1
## 148    C10   beds       1
## 149    M18  faces       0
## 150    M18 houses       1
## 151    M18  pasta       1
## 152    M18   beds       1
## 153    M16  faces       0
## 154    M16 houses       0
## 155    M16  pasta       0
## 156    M16   beds       1
## 157    M23  faces       1
## 158    M23 houses       0
## 159    M23  pasta       1
## 160    M23   beds       1
## 161     C7  faces       0
## 162     C7 houses       1
## 163     C7  pasta       0
## 164     C7   beds       0
## 165    C12  faces       1
## 166    C12 houses       0
## 167    C12  pasta       1
## 168    C12   beds       1
## 169    C15  faces       1
## 170    C15 houses       1
## 171    C15  pasta       1
## 172    C15   beds       1
## 173    M29  faces       0
## 174    M29 houses       1
## 175    M29  pasta       1
## 176    M29   beds       1
## 177    C20  faces       1
## 178    C20 houses       1
## 179    C20  pasta       1
## 180    C20   beds       1
## 181    M11  faces       1
## 182    M11 houses       0
## 183    M11  pasta       1
## 184    M11   beds       1
## 185     C9   beds       1
## 186     C9  faces       1
## 187     C9 houses       1
## 188     C9  pasta       1
## 189    C24  faces       1
## 190    C24 houses       0
## 191    C24  pasta       0
## 192    C24   beds       1
## 193    C22  faces       0
## 194    C22 houses       0
## 195    C22  pasta       1
## 196    C22   beds       1
## 197     C8  faces       1
## 198     C8 houses       1
## 199     C8  pasta       1
## 200     C8   beds       1
## 201     M4  faces       1
## 202     M4 houses       1
## 203     M4  pasta       1
## 204     M4   beds       1
## 205     M6  faces       0
## 206     M6 houses       1
## 207     M6  pasta       1
## 208     M6   beds       0
## 209    C19  faces       1
## 210    C19 houses       0
## 211    C19  pasta       0
## 212    C19   beds       1
## 213     C1  faces       1
## 214     C1 houses       1
## 215     C1  pasta       1
## 216     C1   beds       1
## 217    M19   beds       1
## 218    M19  faces       0
## 219    M19 houses       0
## 220    M19  pasta       1
## 221    C11  faces       1
## 222    C11 houses       0
## 223    C11  pasta       1
## 224    C11   beds       1
## 225     M9  faces       1
## 226     M9 houses       1
## 227     M9  pasta       1
## 228     M9   beds       1
## 229     M2  faces       1
## 230     M2 houses       0
## 231     M2  pasta       1
## 232     M2   beds       1
## 233     C5  faces       1
## 234     C5 houses       1
## 235     C5  pasta       1
## 236     C5   beds       1
## 237    M30   beds       1
## 238    M30  faces       1
## 239    M30 houses       0
## 240    M30  pasta       1
## 241    C13  faces       0
## 242    C13 houses       1
## 243    C13  pasta       0
## 244    C13   beds       1
## 245     C4  faces       1
## 246     C4 houses       1
## 247     C4  pasta       1
## 248     C4   beds       1
## 249    C14  faces       1
## 250    C14 houses       1
## 251    C14  pasta       0
## 252    C14   beds       1
## 253    M17  faces       1
## 254    M17 houses       1
## 255    M17  pasta       1
## 256    M17   beds       1
## 257     C2  faces       1
## 258     C2 houses       1
## 259     C2  pasta       1
## 260     C2   beds       1
## 261    C23  faces       0
## 262    C23 houses       1
## 263    C23  pasta       1
## 264    C23   beds       0
## 265    M20  faces       0
## 266    M20 houses       0
## 267    M20  pasta       1
## 268    M20   beds       1
## 269    M21  faces       1
## 270    M21 houses       1
## 271    M21  pasta       1
## 272    M21   beds       1
## 273    C21  faces       1
## 274    C21 houses       0
## 275    C21  pasta       1
## 276    C21   beds       1
## 277    M24  faces       1
## 278    M24 houses       1
## 279    M24  pasta       1
## 280    M24   beds       1
## 281     M5  faces       0
## 282     M5 houses       0
## 283     M5  pasta       0
## 284     M5   beds       1
## 285     M7  faces       1
## 286     M7 houses       1
## 287     M7  pasta       1
## 288     M7   beds       0
## 289     M8  faces       1
## 290     M8 houses       1
## 291     M8  pasta       1
## 292     M8   beds       1
## 293    C18  faces       0
## 294    C18 houses       1
## 295    C18  pasta       1
## 296    C18   beds       1
## 297    M25  faces       1
## 298    M25 houses       1
## 299    M25  pasta       1
## 300    M25   beds       1
## 301 MSCH47  faces       1
## 302 MSCH47 houses       0
## 303 MSCH47  pasta       1
## 304 MSCH47   beds       0
## 305 MSCH50  faces       0
## 306 MSCH50 houses       0
## 307 MSCH50  pasta       0
## 308 MSCH50   beds       0
## 309 MSCH51  faces       0
## 310 MSCH51 houses       0
## 311 MSCH51  pasta       0
## 312 MSCH51   beds       0
## 313 MSCH44  faces       0
## 314 MSCH44 houses       0
## 315 MSCH44  pasta       0
## 316 MSCH44   beds       0
## 317 MSCH52  faces       0
## 318 MSCH52 houses       1
## 319 MSCH52  pasta       0
## 320 MSCH52   beds       1
## 321 MSCH38  faces       0
## 322 MSCH38 houses       0
## 323 MSCH38  pasta       1
## 324 MSCH38   beds       0
## 325 MSCH43  faces       0
## 326 MSCH43 houses       0
## 327 MSCH43  pasta       0
## 328 MSCH43   beds       0
## 329 MSCH49  faces       0
## 330 MSCH49 houses       0
## 331 MSCH49  pasta       0
## 332 MSCH49   beds       0
## 333 MSCH45  faces       0
## 334 MSCH45 houses       0
## 335 MSCH45  pasta       0
## 336 MSCH45   beds       1
## 337 MSCH42  faces       1
## 338 MSCH42 houses       0
## 339 MSCH42  pasta       0
## 340 MSCH42   beds       0
## 341 MSCH53  faces       1
## 342 MSCH53 houses       1
## 343 MSCH53  pasta       0
## 344 MSCH53   beds       0
## 345  SCH35  faces       0
## 346  SCH35 houses       0
## 347  SCH35  pasta       0
## 348  SCH35   beds       0
## 349 MSCH40  faces       0
## 350 MSCH40 houses       1
## 351 MSCH40  pasta       0
## 352 MSCH40   beds       1
## 353  SCH34  faces       0
## 354  SCH34 houses       0
## 355  SCH34  pasta       0
## 356  SCH34   beds       0
## 357  SCH33  faces       0
## 358  SCH33 houses       0
## 359  SCH33  pasta       0
## 360  SCH33   beds       0
## 361 MSCH41  faces       0
## 362 MSCH41 houses       0
## 363 MSCH41  pasta       0
## 364 MSCH41   beds       0
## 365  SCH37   beds       0
## 366  SCH37  faces       1
## 367  SCH37 houses       0
## 368  SCH37  pasta       1
## 369  SCH32  faces       1
## 370  SCH32 houses       0
## 371  SCH32  pasta       0
## 372  SCH32   beds       0
## 373  SCH36   beds       0
## 374  SCH36  faces       0
## 375  SCH36 houses       1
## 376  SCH36  pasta       1
## 377  SCH11   beds       0
## 378  SCH12  faces       0
## 379  SCH12 houses       0
## 380  SCH12  pasta       0
## 381  SCH12   beds       0
## 382  SCH18  faces       0
## 383  SCH18 houses       0
## 384  SCH18  pasta       0
## 385  SCH18   beds       0
## 386 MSCH48  faces       0
## 387 MSCH48 houses       1
## 388 MSCH48  pasta       0
## 389 MSCH48   beds       0
## 390  SCH25  faces       0
## 391  SCH25 houses       1
## 392  SCH25  pasta       1
## 393  SCH25   beds       0
## 394  SCH31  faces       0
## 395  SCH31 houses       0
## 396  SCH31  pasta       0
## 397  SCH31   beds       0
## 398 MSCH46  faces       0
## 399 MSCH46 houses       0
## 400 MSCH46  pasta       1
## 401 MSCH46   beds       0
## 402  SCH11  faces       1
## 403  SCH11 houses       1
## 404  SCH11  pasta       1
## 405  SCH29  faces       0
## 406  SCH29 houses       0
## 407  SCH29  pasta       0
## 408  SCH29   beds       0
## 409 MSCH39   beds       1
## 410 MSCH39  pasta       0
## 411 MSCH39 houses       0
## 412 MSCH39  faces       0
## 413  SCH28  faces       0
## 414  SCH28 houses       0
## 415  SCH28  pasta       0
## 416  SCH28   beds       0
## 417  SCH22  faces       0
## 418  SCH22 houses       0
## 419  SCH22  pasta       0
## 420  SCH22   beds       1
## 421  SCH24  faces       0
## 422  SCH24 houses       0
## 423  SCH24  pasta       1
## 424  SCH24   beds       0
## 425  SCH27  faces       0
## 426  SCH27 houses       0
## 427  SCH27  pasta       1
## 428  SCH27   beds       0
## 429  SCH17  faces       0
## 430  SCH17 houses       0
## 431  SCH17  pasta       1
## 432  SCH17   beds       0
## 433  SCH10  faces       0
## 434  SCH10 houses       0
## 435  SCH10  pasta       0
## 436  SCH10   beds       1
## 437   SCH9  faces       0
## 438   SCH9 houses       0
## 439   SCH9  pasta       0
## 440   SCH9   beds       0
## 441  SCH20  faces       0
## 442  SCH20 houses       0
## 443  SCH20  pasta       0
## 444  SCH20   beds       0
## 445   SCH6  faces       0
## 446   SCH6 houses       0
## 447   SCH6  pasta       0
## 448   SCH6   beds       0
## 449   SCH7  faces       1
## 450   SCH7 houses       0
## 451   SCH7  pasta       0
## 452   SCH7   beds       0
## 453  SCH15  faces       1
## 454  SCH15 houses       0
## 455  SCH15  pasta       0
## 456  SCH15   beds       0
## 457  SCH30  faces       0
## 458  SCH30 houses       0
## 459  SCH30  pasta       1
## 460  SCH30   beds       0
## 461   SCH3  faces       0
## 462   SCH3 houses       0
## 463   SCH3  pasta       0
## 464   SCH3   beds       0
## 465  SCH26  faces       0
## 466  SCH26 houses       0
## 467  SCH26  pasta       1
## 468  SCH26   beds       0
## 469   SCH8  faces       0
## 470   SCH8 houses       0
## 471   SCH8  pasta       0
## 472   SCH8   beds       0
## 473  SCH16  faces       0
## 474  SCH16 houses       0
## 475  SCH16  pasta       0
## 476  SCH16   beds       1
## 477  SCH14  faces       0
## 478  SCH14 houses       0
## 479  SCH14  pasta       0
## 480  SCH14   beds       1
## 481   SCH2  faces       0
## 482   SCH2 houses       0
## 483   SCH2  pasta       0
## 484   SCH2   beds       0
## 485   SCH5  faces       0
## 486   SCH5 houses       0
## 487   SCH5  pasta       0
## 488   SCH5   beds       0
## 489  SCH13  faces       0
## 490  SCH13 houses       0
## 491  SCH13  pasta       0
## 492  SCH13   beds       0
## 493  SCH21  faces       0
## 494  SCH21 houses       0
## 495  SCH21  pasta       0
## 496  SCH21   beds       0
## 497  SCH19  faces       0
## 498  SCH19 houses       0
## 499  SCH19  pasta       0
## 500  SCH19   beds       1
## 501  SCH23  faces       0
## 502  SCH23 houses       0
## 503  SCH23  pasta       0
## 504  SCH23   beds       0
## 505   SCH1  faces       0
## 506   SCH1 houses       0
## 507   SCH1  pasta       0
## 508   SCH1   beds       0
## 509 MSCH66  faces       0
## 510 MSCH66 houses       0
## 511 MSCH66  pasta       1
## 512 MSCH66   beds       0
## 513 MSCH67  faces       0
## 514 MSCH67 houses       1
## 515 MSCH67  pasta       0
## 516 MSCH67   beds       1
## 517 MSCH68  faces       0
## 518 MSCH68 houses       0
## 519 MSCH68  pasta       0
## 520 MSCH68   beds       0
## 521 MSCH69  faces       0
## 522 MSCH69 houses       1
## 523 MSCH69  pasta       1
## 524 MSCH69   beds       0
## 525 MSCH70  faces       0
## 526 MSCH70 houses       0
## 527 MSCH70  pasta       0
## 528 MSCH70   beds       1
## 529 MSCH71  faces       1
## 530 MSCH71 houses       1
## 531 MSCH71  pasta       1
## 532 MSCH71   beds       0
## 533 MSCH72  faces       1
## 534 MSCH72 houses       1
## 535 MSCH72  pasta       0
## 536 MSCH72   beds       0
## 537 MSCH73  faces       0
## 538 MSCH73 houses       0
## 539 MSCH73  pasta       0
## 540 MSCH73   beds       0
## 541 MSCH74  faces       1
## 542 MSCH74 houses       0
## 543 MSCH74  pasta       0
## 544 MSCH74   beds       1
## 545 MSCH75  faces       0
## 546 MSCH75 houses       0
## 547 MSCH75  pasta       0
## 548 MSCH75   beds       0
## 549 MSCH76  faces       0
## 550 MSCH76 houses       0
## 551 MSCH76  pasta       0
## 552 MSCH76   beds       0
## 553 MSCH77  faces       0
## 554 MSCH77 houses       0
## 555 MSCH77  pasta       0
## 556 MSCH77   beds       1
## 557 MSCH78  faces       0
## 558 MSCH78 houses       0
## 559 MSCH78  pasta       0
## 560 MSCH78   beds       1
## 561 MSCH79  faces       0
## 562 MSCH79 houses       1
## 563 MSCH79  pasta       0
## 564 MSCH79   beds       1
## 565 MSCH80  faces       0
## 566 MSCH80 houses       0
## 567 MSCH80  pasta       0
## 568 MSCH80   beds       0
## 569 MSCH81  faces       1
## 570 MSCH81 houses       0
## 571 MSCH81  pasta       0
## 572 MSCH81   beds       0
## 573 MSCH82  faces       1
## 574 MSCH82 houses       0
## 575 MSCH82  pasta       1
## 576 MSCH82   beds       0
## 577 MSCH83  faces       0
## 578 MSCH83 houses       0
## 579 MSCH83  pasta       1
## 580 MSCH83   beds       0
## 581 MSCH84  faces       0
## 582 MSCH84 houses       0
## 583 MSCH84  pasta       1
## 584 MSCH84   beds       0
## 585 MSCH85  faces       0
## 586 MSCH85 houses       0
## 587 MSCH85  pasta       0
## 588 MSCH85   beds       0
# de-select last three:
select(ps_data, -(1:3)) # - requires parenthetical sequence
##      age condition
## 1   2.00     Label
## 2   2.00     Label
## 3   2.00     Label
## 4   2.00     Label
## 5   2.13     Label
## 6   2.13     Label
## 7   2.13     Label
## 8   2.13     Label
## 9   2.32     Label
## 10  2.32     Label
## 11  2.32     Label
## 12  2.32     Label
## 13  2.38     Label
## 14  2.38     Label
## 15  2.38     Label
## 16  2.38     Label
## 17  2.47     Label
## 18  2.47     Label
## 19  2.47     Label
## 20  2.47     Label
## 21  2.50     Label
## 22  2.50     Label
## 23  2.50     Label
## 24  2.50     Label
## 25  2.58     Label
## 26  2.58     Label
## 27  2.58     Label
## 28  2.58     Label
## 29  2.59     Label
## 30  2.59     Label
## 31  2.59     Label
## 32  2.59     Label
## 33  2.61     Label
## 34  2.61     Label
## 35  2.61     Label
## 36  2.61     Label
## 37  2.72     Label
## 38  2.72     Label
## 39  2.72     Label
## 40  2.72     Label
## 41  2.73     Label
## 42  2.73     Label
## 43  2.73     Label
## 44  2.73     Label
## 45  2.74     Label
## 46  2.74     Label
## 47  2.74     Label
## 48  2.74     Label
## 49  2.79     Label
## 50  2.79     Label
## 51  2.79     Label
## 52  2.79     Label
## 53  2.80     Label
## 54  2.80     Label
## 55  2.80     Label
## 56  2.80     Label
## 57  2.83     Label
## 58  2.83     Label
## 59  2.83     Label
## 60  2.83     Label
## 61  2.83     Label
## 62  2.83     Label
## 63  2.83     Label
## 64  2.83     Label
## 65  2.85     Label
## 66  2.85     Label
## 67  2.85     Label
## 68  2.85     Label
## 69  2.88     Label
## 70  2.88     Label
## 71  2.88     Label
## 72  2.88     Label
## 73  2.88     Label
## 74  2.88     Label
## 75  2.88     Label
## 76  2.88     Label
## 77  2.89     Label
## 78  2.89     Label
## 79  2.89     Label
## 80  2.89     Label
## 81  2.91     Label
## 82  2.91     Label
## 83  2.91     Label
## 84  2.91     Label
## 85  2.95     Label
## 86  2.95     Label
## 87  2.95     Label
## 88  2.95     Label
## 89  2.98     Label
## 90  2.98     Label
## 91  2.98     Label
## 92  2.98     Label
## 93  2.99     Label
## 94  2.99     Label
## 95  2.99     Label
## 96  2.99     Label
## 97  3.00     Label
## 98  3.00     Label
## 99  3.00     Label
## 100 3.00     Label
## 101 3.09     Label
## 102 3.09     Label
## 103 3.09     Label
## 104 3.09     Label
## 105 3.10     Label
## 106 3.10     Label
## 107 3.10     Label
## 108 3.10     Label
## 109 3.19     Label
## 110 3.19     Label
## 111 3.19     Label
## 112 3.19     Label
## 113 3.20     Label
## 114 3.20     Label
## 115 3.20     Label
## 116 3.20     Label
## 117 3.22     Label
## 118 3.22     Label
## 119 3.22     Label
## 120 3.22     Label
## 121 3.24     Label
## 122 3.24     Label
## 123 3.24     Label
## 124 3.24     Label
## 125 3.25     Label
## 126 3.25     Label
## 127 3.25     Label
## 128 3.25     Label
## 129 3.26     Label
## 130 3.26     Label
## 131 3.26     Label
## 132 3.26     Label
## 133 3.28     Label
## 134 3.28     Label
## 135 3.28     Label
## 136 3.28     Label
## 137 3.30     Label
## 138 3.30     Label
## 139 3.30     Label
## 140 3.30     Label
## 141 3.46     Label
## 142 3.46     Label
## 143 3.46     Label
## 144 3.46     Label
## 145 3.46     Label
## 146 3.46     Label
## 147 3.46     Label
## 148 3.46     Label
## 149 3.46     Label
## 150 3.46     Label
## 151 3.46     Label
## 152 3.46     Label
## 153 3.50     Label
## 154 3.50     Label
## 155 3.50     Label
## 156 3.50     Label
## 157 3.52     Label
## 158 3.52     Label
## 159 3.52     Label
## 160 3.52     Label
## 161 3.55     Label
## 162 3.55     Label
## 163 3.55     Label
## 164 3.55     Label
## 165 3.56     Label
## 166 3.56     Label
## 167 3.56     Label
## 168 3.56     Label
## 169 3.59     Label
## 170 3.59     Label
## 171 3.59     Label
## 172 3.59     Label
## 173 3.72     Label
## 174 3.72     Label
## 175 3.72     Label
## 176 3.72     Label
## 177 3.75     Label
## 178 3.75     Label
## 179 3.75     Label
## 180 3.75     Label
## 181 3.82     Label
## 182 3.82     Label
## 183 3.82     Label
## 184 3.82     Label
## 185 3.82     Label
## 186 3.82     Label
## 187 3.82     Label
## 188 3.82     Label
## 189 3.85     Label
## 190 3.85     Label
## 191 3.85     Label
## 192 3.85     Label
## 193 3.92     Label
## 194 3.92     Label
## 195 3.92     Label
## 196 3.92     Label
## 197 3.92     Label
## 198 3.92     Label
## 199 3.92     Label
## 200 3.92     Label
## 201 3.96     Label
## 202 3.96     Label
## 203 3.96     Label
## 204 3.96     Label
## 205 4.50     Label
## 206 4.50     Label
## 207 4.50     Label
## 208 4.50     Label
## 209 4.14     Label
## 210 4.14     Label
## 211 4.14     Label
## 212 4.14     Label
## 213 4.16     Label
## 214 4.16     Label
## 215 4.16     Label
## 216 4.16     Label
## 217 4.16     Label
## 218 4.16     Label
## 219 4.16     Label
## 220 4.16     Label
## 221 4.22     Label
## 222 4.22     Label
## 223 4.22     Label
## 224 4.22     Label
## 225 4.26     Label
## 226 4.26     Label
## 227 4.26     Label
## 228 4.26     Label
## 229 4.28     Label
## 230 4.28     Label
## 231 4.28     Label
## 232 4.28     Label
## 233 4.29     Label
## 234 4.29     Label
## 235 4.29     Label
## 236 4.29     Label
## 237 4.33     Label
## 238 4.33     Label
## 239 4.33     Label
## 240 4.33     Label
## 241 4.38     Label
## 242 4.38     Label
## 243 4.38     Label
## 244 4.38     Label
## 245 4.55     Label
## 246 4.55     Label
## 247 4.55     Label
## 248 4.55     Label
## 249 4.57     Label
## 250 4.57     Label
## 251 4.57     Label
## 252 4.57     Label
## 253 4.58     Label
## 254 4.58     Label
## 255 4.58     Label
## 256 4.58     Label
## 257 4.60     Label
## 258 4.60     Label
## 259 4.60     Label
## 260 4.60     Label
## 261 4.62     Label
## 262 4.62     Label
## 263 4.62     Label
## 264 4.62     Label
## 265 4.64     Label
## 266 4.64     Label
## 267 4.64     Label
## 268 4.64     Label
## 269 4.64     Label
## 270 4.64     Label
## 271 4.64     Label
## 272 4.64     Label
## 273 4.73     Label
## 274 4.73     Label
## 275 4.73     Label
## 276 4.73     Label
## 277 4.82     Label
## 278 4.82     Label
## 279 4.82     Label
## 280 4.82     Label
## 281 4.84     Label
## 282 4.84     Label
## 283 4.84     Label
## 284 4.84     Label
## 285 4.89     Label
## 286 4.89     Label
## 287 4.89     Label
## 288 4.89     Label
## 289 4.89     Label
## 290 4.89     Label
## 291 4.89     Label
## 292 4.89     Label
## 293 4.95     Label
## 294 4.95     Label
## 295 4.95     Label
## 296 4.95     Label
## 297 4.96     Label
## 298 4.96     Label
## 299 4.96     Label
## 300 4.96     Label
## 301 2.01  No Label
## 302 2.01  No Label
## 303 2.01  No Label
## 304 2.01  No Label
## 305 2.03  No Label
## 306 2.03  No Label
## 307 2.03  No Label
## 308 2.03  No Label
## 309 2.07  No Label
## 310 2.07  No Label
## 311 2.07  No Label
## 312 2.07  No Label
## 313 2.25  No Label
## 314 2.25  No Label
## 315 2.25  No Label
## 316 2.25  No Label
## 317 2.50  No Label
## 318 2.50  No Label
## 319 2.50  No Label
## 320 2.50  No Label
## 321 2.59  No Label
## 322 2.59  No Label
## 323 2.59  No Label
## 324 2.59  No Label
## 325 2.71  No Label
## 326 2.71  No Label
## 327 2.71  No Label
## 328 2.71  No Label
## 329 2.88  No Label
## 330 2.88  No Label
## 331 2.88  No Label
## 332 2.88  No Label
## 333 2.90  No Label
## 334 2.90  No Label
## 335 2.90  No Label
## 336 2.90  No Label
## 337 2.93  No Label
## 338 2.93  No Label
## 339 2.93  No Label
## 340 2.93  No Label
## 341 2.99  No Label
## 342 2.99  No Label
## 343 2.99  No Label
## 344 2.99  No Label
## 345 3.02  No Label
## 346 3.02  No Label
## 347 3.02  No Label
## 348 3.02  No Label
## 349 3.02  No Label
## 350 3.02  No Label
## 351 3.02  No Label
## 352 3.02  No Label
## 353 3.06  No Label
## 354 3.06  No Label
## 355 3.06  No Label
## 356 3.06  No Label
## 357 3.06  No Label
## 358 3.06  No Label
## 359 3.06  No Label
## 360 3.06  No Label
## 361 3.18  No Label
## 362 3.18  No Label
## 363 3.18  No Label
## 364 3.18  No Label
## 365 3.27  No Label
## 366 3.27  No Label
## 367 3.27  No Label
## 368 3.27  No Label
## 369 3.27  No Label
## 370 3.27  No Label
## 371 3.27  No Label
## 372 3.27  No Label
## 373 3.33  No Label
## 374 3.33  No Label
## 375 3.33  No Label
## 376 3.33  No Label
## 377 3.41  No Label
## 378 3.41  No Label
## 379 3.41  No Label
## 380 3.41  No Label
## 381 3.41  No Label
## 382 3.45  No Label
## 383 3.45  No Label
## 384 3.45  No Label
## 385 3.45  No Label
## 386 3.50  No Label
## 387 3.50  No Label
## 388 3.50  No Label
## 389 3.50  No Label
## 390 3.54  No Label
## 391 3.54  No Label
## 392 3.54  No Label
## 393 3.54  No Label
## 394 3.71  No Label
## 395 3.71  No Label
## 396 3.71  No Label
## 397 3.71  No Label
## 398 3.76  No Label
## 399 3.76  No Label
## 400 3.76  No Label
## 401 3.76  No Label
## 402 3.82  No Label
## 403 3.82  No Label
## 404 3.82  No Label
## 405 3.83  No Label
## 406 3.83  No Label
## 407 3.83  No Label
## 408 3.83  No Label
## 409 3.93  No Label
## 410 3.93  No Label
## 411 3.94  No Label
## 412 3.94  No Label
## 413 4.02  No Label
## 414 4.02  No Label
## 415 4.02  No Label
## 416 4.02  No Label
## 417 4.02  No Label
## 418 4.02  No Label
## 419 4.02  No Label
## 420 4.02  No Label
## 421 4.07  No Label
## 422 4.07  No Label
## 423 4.07  No Label
## 424 4.07  No Label
## 425 4.09  No Label
## 426 4.09  No Label
## 427 4.09  No Label
## 428 4.09  No Label
## 429 4.25  No Label
## 430 4.25  No Label
## 431 4.25  No Label
## 432 4.25  No Label
## 433 4.32  No Label
## 434 4.32  No Label
## 435 4.32  No Label
## 436 4.32  No Label
## 437 4.37  No Label
## 438 4.37  No Label
## 439 4.37  No Label
## 440 4.37  No Label
## 441 4.39  No Label
## 442 4.39  No Label
## 443 4.39  No Label
## 444 4.39  No Label
## 445 4.41  No Label
## 446 4.41  No Label
## 447 4.41  No Label
## 448 4.41  No Label
## 449 4.41  No Label
## 450 4.41  No Label
## 451 4.41  No Label
## 452 4.41  No Label
## 453 4.42  No Label
## 454 4.42  No Label
## 455 4.42  No Label
## 456 4.42  No Label
## 457 4.44  No Label
## 458 4.44  No Label
## 459 4.44  No Label
## 460 4.44  No Label
## 461 4.47  No Label
## 462 4.47  No Label
## 463 4.47  No Label
## 464 4.47  No Label
## 465 4.47  No Label
## 466 4.47  No Label
## 467 4.47  No Label
## 468 4.47  No Label
## 469 4.52  No Label
## 470 4.52  No Label
## 471 4.52  No Label
## 472 4.52  No Label
## 473 4.55  No Label
## 474 4.55  No Label
## 475 4.55  No Label
## 476 4.55  No Label
## 477 4.58  No Label
## 478 4.58  No Label
## 479 4.58  No Label
## 480 4.58  No Label
## 481 4.61  No Label
## 482 4.61  No Label
## 483 4.61  No Label
## 484 4.61  No Label
## 485 4.61  No Label
## 486 4.61  No Label
## 487 4.61  No Label
## 488 4.61  No Label
## 489 4.75  No Label
## 490 4.75  No Label
## 491 4.75  No Label
## 492 4.75  No Label
## 493 4.76  No Label
## 494 4.76  No Label
## 495 4.76  No Label
## 496 4.76  No Label
## 497 4.79  No Label
## 498 4.79  No Label
## 499 4.79  No Label
## 500 4.79  No Label
## 501 4.82  No Label
## 502 4.82  No Label
## 503 4.82  No Label
## 504 4.82  No Label
## 505 4.82  No Label
## 506 4.82  No Label
## 507 4.82  No Label
## 508 4.82  No Label
## 509 3.50  No Label
## 510 3.50  No Label
## 511 3.50  No Label
## 512 3.50  No Label
## 513 3.24  No Label
## 514 3.24  No Label
## 515 3.24  No Label
## 516 3.24  No Label
## 517 3.94  No Label
## 518 3.94  No Label
## 519 3.94  No Label
## 520 3.94  No Label
## 521 2.72  No Label
## 522 2.72  No Label
## 523 2.72  No Label
## 524 2.72  No Label
## 525 2.31  No Label
## 526 2.31  No Label
## 527 2.31  No Label
## 528 2.31  No Label
## 529 3.14  No Label
## 530 3.14  No Label
## 531 3.14  No Label
## 532 3.14  No Label
## 533 3.72  No Label
## 534 3.72  No Label
## 535 3.72  No Label
## 536 3.72  No Label
## 537 3.10  No Label
## 538 3.10  No Label
## 539 3.10  No Label
## 540 3.10  No Label
## 541 2.34  No Label
## 542 2.34  No Label
## 543 2.34  No Label
## 544 2.34  No Label
## 545 3.67  No Label
## 546 3.67  No Label
## 547 3.67  No Label
## 548 3.66  No Label
## 549 2.58  No Label
## 550 2.58  No Label
## 551 2.58  No Label
## 552 2.58  No Label
## 553 2.55  No Label
## 554 2.55  No Label
## 555 2.55  No Label
## 556 2.55  No Label
## 557 2.43  No Label
## 558 2.43  No Label
## 559 2.43  No Label
## 560 2.43  No Label
## 561 2.70  No Label
## 562 2.70  No Label
## 563 2.70  No Label
## 564 2.70  No Label
## 565 2.76  No Label
## 566 2.76  No Label
## 567 2.76  No Label
## 568 2.76  No Label
## 569 2.84  No Label
## 570 2.84  No Label
## 571 2.84  No Label
## 572 2.84  No Label
## 573 2.46  No Label
## 574 2.46  No Label
## 575 2.46  No Label
## 576 2.46  No Label
## 577 2.37  No Label
## 578 2.37  No Label
## 579 2.37  No Label
## 580 2.37  No Label
## 581 2.83  No Label
## 582 2.83  No Label
## 583 2.83  No Label
## 584 2.83  No Label
## 585 2.69  No Label
## 586 2.69  No Label
## 587 2.69  No Label
## 588 2.69  No Label

And you can even use ranges of variable names.

# select first three
select(ps_data, subid:correct)
##      subid   item correct
## 1      M22  faces       1
## 2      M22 houses       1
## 3      M22  pasta       0
## 4      M22   beds       0
## 5      T22   beds       0
## 6      T22  faces       0
## 7      T22 houses       1
## 8      T22  pasta       1
## 9      T17  pasta       0
## 10     T17  faces       0
## 11     T17 houses       0
## 12     T17   beds       0
## 13      M3  faces       0
## 14      M3 houses       1
## 15      M3  pasta       1
## 16      M3   beds       1
## 17     T19  faces       0
## 18     T19 houses       0
## 19     T19  pasta       1
## 20     T19   beds       1
## 21     T20  faces       1
## 22     T20 houses       1
## 23     T20  pasta       0
## 24     T20   beds       1
## 25     T21  faces       1
## 26     T21 houses       1
## 27     T21  pasta       1
## 28     T21   beds       0
## 29     M26  faces       1
## 30     M26 houses       1
## 31     M26  pasta       0
## 32     M26   beds       1
## 33     T18  faces       1
## 34     T18 houses       0
## 35     T18  pasta       1
## 36     T18   beds       0
## 37     T12   beds       0
## 38     T12  faces       0
## 39     T12 houses       1
## 40     T12  pasta       0
## 41     T16  faces       1
## 42     T16 houses       0
## 43     T16  pasta       1
## 44     T16   beds       1
## 45      T7  faces       1
## 46      T7 houses       0
## 47      T7  pasta       0
## 48      T7   beds       0
## 49      T9 houses       0
## 50      T9  faces       1
## 51      T9  pasta       0
## 52      T9   beds       1
## 53      T5  faces       1
## 54      T5 houses       1
## 55      T5  pasta       0
## 56      T5   beds       1
## 57     T14  faces       1
## 58     T14 houses       1
## 59     T14  pasta       0
## 60     T14   beds       1
## 61      T2 houses       0
## 62      T2  faces       0
## 63      T2  pasta       1
## 64      T2   beds       1
## 65     T15  faces       0
## 66     T15 houses       0
## 67     T15  pasta       1
## 68     T15   beds       0
## 69     M13 houses       0
## 70     M13   beds       1
## 71     M13  faces       1
## 72     M13  pasta       0
## 73     M12  faces       1
## 74     M12 houses       0
## 75     M12  pasta       1
## 76     M12   beds       0
## 77     T13   beds       0
## 78     T13  faces       0
## 79     T13 houses       1
## 80     T13  pasta       1
## 81      T8  faces       1
## 82      T8 houses       0
## 83      T8  pasta       1
## 84      T8   beds       1
## 85      T1  faces       1
## 86      T1 houses       0
## 87      T1  pasta       0
## 88      T1   beds       1
## 89     M15  faces       1
## 90     M15 houses       1
## 91     M15  pasta       1
## 92     M15   beds       1
## 93     T11  faces       1
## 94     T11 houses       0
## 95     T11  pasta       1
## 96     T11   beds       1
## 97     T10  faces       0
## 98     T10 houses       1
## 99     T10  pasta       1
## 100    T10   beds       1
## 101     T3  faces       1
## 102     T3 houses       1
## 103     T3  pasta       1
## 104     T3   beds       1
## 105     T6  faces       1
## 106     T6 houses       1
## 107     T6  pasta       1
## 108     T6   beds       1
## 109    M32   beds       1
## 110    M32  faces       1
## 111    M32 houses       0
## 112    M32  pasta       1
## 113     M1  faces       0
## 114     M1   beds       1
## 115     M1  pasta       0
## 116     M1 houses       0
## 117    C16  faces       0
## 118    C16 houses       0
## 119    C16  pasta       1
## 120    C16   beds       1
## 121     T4  faces       1
## 122     T4 houses       0
## 123     T4  pasta       0
## 124     T4   beds       1
## 125    C17  faces       1
## 126    C17 houses       0
## 127    C17  pasta       1
## 128    C17   beds       0
## 129     C6  faces       0
## 130     C6 houses       1
## 131     C6  pasta       1
## 132     C6   beds       1
## 133    M10  faces       1
## 134    M10 houses       1
## 135    M10   beds       1
## 136    M10  pasta       1
## 137    M31  faces       0
## 138    M31 houses       1
## 139    M31  pasta       1
## 140    M31   beds       1
## 141     C3 houses       0
## 142     C3  pasta       1
## 143     C3   beds       1
## 144     C3  faces       1
## 145    C10  faces       0
## 146    C10 houses       0
## 147    C10  pasta       1
## 148    C10   beds       1
## 149    M18  faces       0
## 150    M18 houses       1
## 151    M18  pasta       1
## 152    M18   beds       1
## 153    M16  faces       0
## 154    M16 houses       0
## 155    M16  pasta       0
## 156    M16   beds       1
## 157    M23  faces       1
## 158    M23 houses       0
## 159    M23  pasta       1
## 160    M23   beds       1
## 161     C7  faces       0
## 162     C7 houses       1
## 163     C7  pasta       0
## 164     C7   beds       0
## 165    C12  faces       1
## 166    C12 houses       0
## 167    C12  pasta       1
## 168    C12   beds       1
## 169    C15  faces       1
## 170    C15 houses       1
## 171    C15  pasta       1
## 172    C15   beds       1
## 173    M29  faces       0
## 174    M29 houses       1
## 175    M29  pasta       1
## 176    M29   beds       1
## 177    C20  faces       1
## 178    C20 houses       1
## 179    C20  pasta       1
## 180    C20   beds       1
## 181    M11  faces       1
## 182    M11 houses       0
## 183    M11  pasta       1
## 184    M11   beds       1
## 185     C9   beds       1
## 186     C9  faces       1
## 187     C9 houses       1
## 188     C9  pasta       1
## 189    C24  faces       1
## 190    C24 houses       0
## 191    C24  pasta       0
## 192    C24   beds       1
## 193    C22  faces       0
## 194    C22 houses       0
## 195    C22  pasta       1
## 196    C22   beds       1
## 197     C8  faces       1
## 198     C8 houses       1
## 199     C8  pasta       1
## 200     C8   beds       1
## 201     M4  faces       1
## 202     M4 houses       1
## 203     M4  pasta       1
## 204     M4   beds       1
## 205     M6  faces       0
## 206     M6 houses       1
## 207     M6  pasta       1
## 208     M6   beds       0
## 209    C19  faces       1
## 210    C19 houses       0
## 211    C19  pasta       0
## 212    C19   beds       1
## 213     C1  faces       1
## 214     C1 houses       1
## 215     C1  pasta       1
## 216     C1   beds       1
## 217    M19   beds       1
## 218    M19  faces       0
## 219    M19 houses       0
## 220    M19  pasta       1
## 221    C11  faces       1
## 222    C11 houses       0
## 223    C11  pasta       1
## 224    C11   beds       1
## 225     M9  faces       1
## 226     M9 houses       1
## 227     M9  pasta       1
## 228     M9   beds       1
## 229     M2  faces       1
## 230     M2 houses       0
## 231     M2  pasta       1
## 232     M2   beds       1
## 233     C5  faces       1
## 234     C5 houses       1
## 235     C5  pasta       1
## 236     C5   beds       1
## 237    M30   beds       1
## 238    M30  faces       1
## 239    M30 houses       0
## 240    M30  pasta       1
## 241    C13  faces       0
## 242    C13 houses       1
## 243    C13  pasta       0
## 244    C13   beds       1
## 245     C4  faces       1
## 246     C4 houses       1
## 247     C4  pasta       1
## 248     C4   beds       1
## 249    C14  faces       1
## 250    C14 houses       1
## 251    C14  pasta       0
## 252    C14   beds       1
## 253    M17  faces       1
## 254    M17 houses       1
## 255    M17  pasta       1
## 256    M17   beds       1
## 257     C2  faces       1
## 258     C2 houses       1
## 259     C2  pasta       1
## 260     C2   beds       1
## 261    C23  faces       0
## 262    C23 houses       1
## 263    C23  pasta       1
## 264    C23   beds       0
## 265    M20  faces       0
## 266    M20 houses       0
## 267    M20  pasta       1
## 268    M20   beds       1
## 269    M21  faces       1
## 270    M21 houses       1
## 271    M21  pasta       1
## 272    M21   beds       1
## 273    C21  faces       1
## 274    C21 houses       0
## 275    C21  pasta       1
## 276    C21   beds       1
## 277    M24  faces       1
## 278    M24 houses       1
## 279    M24  pasta       1
## 280    M24   beds       1
## 281     M5  faces       0
## 282     M5 houses       0
## 283     M5  pasta       0
## 284     M5   beds       1
## 285     M7  faces       1
## 286     M7 houses       1
## 287     M7  pasta       1
## 288     M7   beds       0
## 289     M8  faces       1
## 290     M8 houses       1
## 291     M8  pasta       1
## 292     M8   beds       1
## 293    C18  faces       0
## 294    C18 houses       1
## 295    C18  pasta       1
## 296    C18   beds       1
## 297    M25  faces       1
## 298    M25 houses       1
## 299    M25  pasta       1
## 300    M25   beds       1
## 301 MSCH47  faces       1
## 302 MSCH47 houses       0
## 303 MSCH47  pasta       1
## 304 MSCH47   beds       0
## 305 MSCH50  faces       0
## 306 MSCH50 houses       0
## 307 MSCH50  pasta       0
## 308 MSCH50   beds       0
## 309 MSCH51  faces       0
## 310 MSCH51 houses       0
## 311 MSCH51  pasta       0
## 312 MSCH51   beds       0
## 313 MSCH44  faces       0
## 314 MSCH44 houses       0
## 315 MSCH44  pasta       0
## 316 MSCH44   beds       0
## 317 MSCH52  faces       0
## 318 MSCH52 houses       1
## 319 MSCH52  pasta       0
## 320 MSCH52   beds       1
## 321 MSCH38  faces       0
## 322 MSCH38 houses       0
## 323 MSCH38  pasta       1
## 324 MSCH38   beds       0
## 325 MSCH43  faces       0
## 326 MSCH43 houses       0
## 327 MSCH43  pasta       0
## 328 MSCH43   beds       0
## 329 MSCH49  faces       0
## 330 MSCH49 houses       0
## 331 MSCH49  pasta       0
## 332 MSCH49   beds       0
## 333 MSCH45  faces       0
## 334 MSCH45 houses       0
## 335 MSCH45  pasta       0
## 336 MSCH45   beds       1
## 337 MSCH42  faces       1
## 338 MSCH42 houses       0
## 339 MSCH42  pasta       0
## 340 MSCH42   beds       0
## 341 MSCH53  faces       1
## 342 MSCH53 houses       1
## 343 MSCH53  pasta       0
## 344 MSCH53   beds       0
## 345  SCH35  faces       0
## 346  SCH35 houses       0
## 347  SCH35  pasta       0
## 348  SCH35   beds       0
## 349 MSCH40  faces       0
## 350 MSCH40 houses       1
## 351 MSCH40  pasta       0
## 352 MSCH40   beds       1
## 353  SCH34  faces       0
## 354  SCH34 houses       0
## 355  SCH34  pasta       0
## 356  SCH34   beds       0
## 357  SCH33  faces       0
## 358  SCH33 houses       0
## 359  SCH33  pasta       0
## 360  SCH33   beds       0
## 361 MSCH41  faces       0
## 362 MSCH41 houses       0
## 363 MSCH41  pasta       0
## 364 MSCH41   beds       0
## 365  SCH37   beds       0
## 366  SCH37  faces       1
## 367  SCH37 houses       0
## 368  SCH37  pasta       1
## 369  SCH32  faces       1
## 370  SCH32 houses       0
## 371  SCH32  pasta       0
## 372  SCH32   beds       0
## 373  SCH36   beds       0
## 374  SCH36  faces       0
## 375  SCH36 houses       1
## 376  SCH36  pasta       1
## 377  SCH11   beds       0
## 378  SCH12  faces       0
## 379  SCH12 houses       0
## 380  SCH12  pasta       0
## 381  SCH12   beds       0
## 382  SCH18  faces       0
## 383  SCH18 houses       0
## 384  SCH18  pasta       0
## 385  SCH18   beds       0
## 386 MSCH48  faces       0
## 387 MSCH48 houses       1
## 388 MSCH48  pasta       0
## 389 MSCH48   beds       0
## 390  SCH25  faces       0
## 391  SCH25 houses       1
## 392  SCH25  pasta       1
## 393  SCH25   beds       0
## 394  SCH31  faces       0
## 395  SCH31 houses       0
## 396  SCH31  pasta       0
## 397  SCH31   beds       0
## 398 MSCH46  faces       0
## 399 MSCH46 houses       0
## 400 MSCH46  pasta       1
## 401 MSCH46   beds       0
## 402  SCH11  faces       1
## 403  SCH11 houses       1
## 404  SCH11  pasta       1
## 405  SCH29  faces       0
## 406  SCH29 houses       0
## 407  SCH29  pasta       0
## 408  SCH29   beds       0
## 409 MSCH39   beds       1
## 410 MSCH39  pasta       0
## 411 MSCH39 houses       0
## 412 MSCH39  faces       0
## 413  SCH28  faces       0
## 414  SCH28 houses       0
## 415  SCH28  pasta       0
## 416  SCH28   beds       0
## 417  SCH22  faces       0
## 418  SCH22 houses       0
## 419  SCH22  pasta       0
## 420  SCH22   beds       1
## 421  SCH24  faces       0
## 422  SCH24 houses       0
## 423  SCH24  pasta       1
## 424  SCH24   beds       0
## 425  SCH27  faces       0
## 426  SCH27 houses       0
## 427  SCH27  pasta       1
## 428  SCH27   beds       0
## 429  SCH17  faces       0
## 430  SCH17 houses       0
## 431  SCH17  pasta       1
## 432  SCH17   beds       0
## 433  SCH10  faces       0
## 434  SCH10 houses       0
## 435  SCH10  pasta       0
## 436  SCH10   beds       1
## 437   SCH9  faces       0
## 438   SCH9 houses       0
## 439   SCH9  pasta       0
## 440   SCH9   beds       0
## 441  SCH20  faces       0
## 442  SCH20 houses       0
## 443  SCH20  pasta       0
## 444  SCH20   beds       0
## 445   SCH6  faces       0
## 446   SCH6 houses       0
## 447   SCH6  pasta       0
## 448   SCH6   beds       0
## 449   SCH7  faces       1
## 450   SCH7 houses       0
## 451   SCH7  pasta       0
## 452   SCH7   beds       0
## 453  SCH15  faces       1
## 454  SCH15 houses       0
## 455  SCH15  pasta       0
## 456  SCH15   beds       0
## 457  SCH30  faces       0
## 458  SCH30 houses       0
## 459  SCH30  pasta       1
## 460  SCH30   beds       0
## 461   SCH3  faces       0
## 462   SCH3 houses       0
## 463   SCH3  pasta       0
## 464   SCH3   beds       0
## 465  SCH26  faces       0
## 466  SCH26 houses       0
## 467  SCH26  pasta       1
## 468  SCH26   beds       0
## 469   SCH8  faces       0
## 470   SCH8 houses       0
## 471   SCH8  pasta       0
## 472   SCH8   beds       0
## 473  SCH16  faces       0
## 474  SCH16 houses       0
## 475  SCH16  pasta       0
## 476  SCH16   beds       1
## 477  SCH14  faces       0
## 478  SCH14 houses       0
## 479  SCH14  pasta       0
## 480  SCH14   beds       1
## 481   SCH2  faces       0
## 482   SCH2 houses       0
## 483   SCH2  pasta       0
## 484   SCH2   beds       0
## 485   SCH5  faces       0
## 486   SCH5 houses       0
## 487   SCH5  pasta       0
## 488   SCH5   beds       0
## 489  SCH13  faces       0
## 490  SCH13 houses       0
## 491  SCH13  pasta       0
## 492  SCH13   beds       0
## 493  SCH21  faces       0
## 494  SCH21 houses       0
## 495  SCH21  pasta       0
## 496  SCH21   beds       0
## 497  SCH19  faces       0
## 498  SCH19 houses       0
## 499  SCH19  pasta       0
## 500  SCH19   beds       1
## 501  SCH23  faces       0
## 502  SCH23 houses       0
## 503  SCH23  pasta       0
## 504  SCH23   beds       0
## 505   SCH1  faces       0
## 506   SCH1 houses       0
## 507   SCH1  pasta       0
## 508   SCH1   beds       0
## 509 MSCH66  faces       0
## 510 MSCH66 houses       0
## 511 MSCH66  pasta       1
## 512 MSCH66   beds       0
## 513 MSCH67  faces       0
## 514 MSCH67 houses       1
## 515 MSCH67  pasta       0
## 516 MSCH67   beds       1
## 517 MSCH68  faces       0
## 518 MSCH68 houses       0
## 519 MSCH68  pasta       0
## 520 MSCH68   beds       0
## 521 MSCH69  faces       0
## 522 MSCH69 houses       1
## 523 MSCH69  pasta       1
## 524 MSCH69   beds       0
## 525 MSCH70  faces       0
## 526 MSCH70 houses       0
## 527 MSCH70  pasta       0
## 528 MSCH70   beds       1
## 529 MSCH71  faces       1
## 530 MSCH71 houses       1
## 531 MSCH71  pasta       1
## 532 MSCH71   beds       0
## 533 MSCH72  faces       1
## 534 MSCH72 houses       1
## 535 MSCH72  pasta       0
## 536 MSCH72   beds       0
## 537 MSCH73  faces       0
## 538 MSCH73 houses       0
## 539 MSCH73  pasta       0
## 540 MSCH73   beds       0
## 541 MSCH74  faces       1
## 542 MSCH74 houses       0
## 543 MSCH74  pasta       0
## 544 MSCH74   beds       1
## 545 MSCH75  faces       0
## 546 MSCH75 houses       0
## 547 MSCH75  pasta       0
## 548 MSCH75   beds       0
## 549 MSCH76  faces       0
## 550 MSCH76 houses       0
## 551 MSCH76  pasta       0
## 552 MSCH76   beds       0
## 553 MSCH77  faces       0
## 554 MSCH77 houses       0
## 555 MSCH77  pasta       0
## 556 MSCH77   beds       1
## 557 MSCH78  faces       0
## 558 MSCH78 houses       0
## 559 MSCH78  pasta       0
## 560 MSCH78   beds       1
## 561 MSCH79  faces       0
## 562 MSCH79 houses       1
## 563 MSCH79  pasta       0
## 564 MSCH79   beds       1
## 565 MSCH80  faces       0
## 566 MSCH80 houses       0
## 567 MSCH80  pasta       0
## 568 MSCH80   beds       0
## 569 MSCH81  faces       1
## 570 MSCH81 houses       0
## 571 MSCH81  pasta       0
## 572 MSCH81   beds       0
## 573 MSCH82  faces       1
## 574 MSCH82 houses       0
## 575 MSCH82  pasta       1
## 576 MSCH82   beds       0
## 577 MSCH83  faces       0
## 578 MSCH83 houses       0
## 579 MSCH83  pasta       1
## 580 MSCH83   beds       0
## 581 MSCH84  faces       0
## 582 MSCH84 houses       0
## 583 MSCH84  pasta       1
## 584 MSCH84   beds       0
## 585 MSCH85  faces       0
## 586 MSCH85 houses       0
## 587 MSCH85  pasta       0
## 588 MSCH85   beds       0
# deselect first three
select(ps_data, -(subid:correct))
##      age condition
## 1   2.00     Label
## 2   2.00     Label
## 3   2.00     Label
## 4   2.00     Label
## 5   2.13     Label
## 6   2.13     Label
## 7   2.13     Label
## 8   2.13     Label
## 9   2.32     Label
## 10  2.32     Label
## 11  2.32     Label
## 12  2.32     Label
## 13  2.38     Label
## 14  2.38     Label
## 15  2.38     Label
## 16  2.38     Label
## 17  2.47     Label
## 18  2.47     Label
## 19  2.47     Label
## 20  2.47     Label
## 21  2.50     Label
## 22  2.50     Label
## 23  2.50     Label
## 24  2.50     Label
## 25  2.58     Label
## 26  2.58     Label
## 27  2.58     Label
## 28  2.58     Label
## 29  2.59     Label
## 30  2.59     Label
## 31  2.59     Label
## 32  2.59     Label
## 33  2.61     Label
## 34  2.61     Label
## 35  2.61     Label
## 36  2.61     Label
## 37  2.72     Label
## 38  2.72     Label
## 39  2.72     Label
## 40  2.72     Label
## 41  2.73     Label
## 42  2.73     Label
## 43  2.73     Label
## 44  2.73     Label
## 45  2.74     Label
## 46  2.74     Label
## 47  2.74     Label
## 48  2.74     Label
## 49  2.79     Label
## 50  2.79     Label
## 51  2.79     Label
## 52  2.79     Label
## 53  2.80     Label
## 54  2.80     Label
## 55  2.80     Label
## 56  2.80     Label
## 57  2.83     Label
## 58  2.83     Label
## 59  2.83     Label
## 60  2.83     Label
## 61  2.83     Label
## 62  2.83     Label
## 63  2.83     Label
## 64  2.83     Label
## 65  2.85     Label
## 66  2.85     Label
## 67  2.85     Label
## 68  2.85     Label
## 69  2.88     Label
## 70  2.88     Label
## 71  2.88     Label
## 72  2.88     Label
## 73  2.88     Label
## 74  2.88     Label
## 75  2.88     Label
## 76  2.88     Label
## 77  2.89     Label
## 78  2.89     Label
## 79  2.89     Label
## 80  2.89     Label
## 81  2.91     Label
## 82  2.91     Label
## 83  2.91     Label
## 84  2.91     Label
## 85  2.95     Label
## 86  2.95     Label
## 87  2.95     Label
## 88  2.95     Label
## 89  2.98     Label
## 90  2.98     Label
## 91  2.98     Label
## 92  2.98     Label
## 93  2.99     Label
## 94  2.99     Label
## 95  2.99     Label
## 96  2.99     Label
## 97  3.00     Label
## 98  3.00     Label
## 99  3.00     Label
## 100 3.00     Label
## 101 3.09     Label
## 102 3.09     Label
## 103 3.09     Label
## 104 3.09     Label
## 105 3.10     Label
## 106 3.10     Label
## 107 3.10     Label
## 108 3.10     Label
## 109 3.19     Label
## 110 3.19     Label
## 111 3.19     Label
## 112 3.19     Label
## 113 3.20     Label
## 114 3.20     Label
## 115 3.20     Label
## 116 3.20     Label
## 117 3.22     Label
## 118 3.22     Label
## 119 3.22     Label
## 120 3.22     Label
## 121 3.24     Label
## 122 3.24     Label
## 123 3.24     Label
## 124 3.24     Label
## 125 3.25     Label
## 126 3.25     Label
## 127 3.25     Label
## 128 3.25     Label
## 129 3.26     Label
## 130 3.26     Label
## 131 3.26     Label
## 132 3.26     Label
## 133 3.28     Label
## 134 3.28     Label
## 135 3.28     Label
## 136 3.28     Label
## 137 3.30     Label
## 138 3.30     Label
## 139 3.30     Label
## 140 3.30     Label
## 141 3.46     Label
## 142 3.46     Label
## 143 3.46     Label
## 144 3.46     Label
## 145 3.46     Label
## 146 3.46     Label
## 147 3.46     Label
## 148 3.46     Label
## 149 3.46     Label
## 150 3.46     Label
## 151 3.46     Label
## 152 3.46     Label
## 153 3.50     Label
## 154 3.50     Label
## 155 3.50     Label
## 156 3.50     Label
## 157 3.52     Label
## 158 3.52     Label
## 159 3.52     Label
## 160 3.52     Label
## 161 3.55     Label
## 162 3.55     Label
## 163 3.55     Label
## 164 3.55     Label
## 165 3.56     Label
## 166 3.56     Label
## 167 3.56     Label
## 168 3.56     Label
## 169 3.59     Label
## 170 3.59     Label
## 171 3.59     Label
## 172 3.59     Label
## 173 3.72     Label
## 174 3.72     Label
## 175 3.72     Label
## 176 3.72     Label
## 177 3.75     Label
## 178 3.75     Label
## 179 3.75     Label
## 180 3.75     Label
## 181 3.82     Label
## 182 3.82     Label
## 183 3.82     Label
## 184 3.82     Label
## 185 3.82     Label
## 186 3.82     Label
## 187 3.82     Label
## 188 3.82     Label
## 189 3.85     Label
## 190 3.85     Label
## 191 3.85     Label
## 192 3.85     Label
## 193 3.92     Label
## 194 3.92     Label
## 195 3.92     Label
## 196 3.92     Label
## 197 3.92     Label
## 198 3.92     Label
## 199 3.92     Label
## 200 3.92     Label
## 201 3.96     Label
## 202 3.96     Label
## 203 3.96     Label
## 204 3.96     Label
## 205 4.50     Label
## 206 4.50     Label
## 207 4.50     Label
## 208 4.50     Label
## 209 4.14     Label
## 210 4.14     Label
## 211 4.14     Label
## 212 4.14     Label
## 213 4.16     Label
## 214 4.16     Label
## 215 4.16     Label
## 216 4.16     Label
## 217 4.16     Label
## 218 4.16     Label
## 219 4.16     Label
## 220 4.16     Label
## 221 4.22     Label
## 222 4.22     Label
## 223 4.22     Label
## 224 4.22     Label
## 225 4.26     Label
## 226 4.26     Label
## 227 4.26     Label
## 228 4.26     Label
## 229 4.28     Label
## 230 4.28     Label
## 231 4.28     Label
## 232 4.28     Label
## 233 4.29     Label
## 234 4.29     Label
## 235 4.29     Label
## 236 4.29     Label
## 237 4.33     Label
## 238 4.33     Label
## 239 4.33     Label
## 240 4.33     Label
## 241 4.38     Label
## 242 4.38     Label
## 243 4.38     Label
## 244 4.38     Label
## 245 4.55     Label
## 246 4.55     Label
## 247 4.55     Label
## 248 4.55     Label
## 249 4.57     Label
## 250 4.57     Label
## 251 4.57     Label
## 252 4.57     Label
## 253 4.58     Label
## 254 4.58     Label
## 255 4.58     Label
## 256 4.58     Label
## 257 4.60     Label
## 258 4.60     Label
## 259 4.60     Label
## 260 4.60     Label
## 261 4.62     Label
## 262 4.62     Label
## 263 4.62     Label
## 264 4.62     Label
## 265 4.64     Label
## 266 4.64     Label
## 267 4.64     Label
## 268 4.64     Label
## 269 4.64     Label
## 270 4.64     Label
## 271 4.64     Label
## 272 4.64     Label
## 273 4.73     Label
## 274 4.73     Label
## 275 4.73     Label
## 276 4.73     Label
## 277 4.82     Label
## 278 4.82     Label
## 279 4.82     Label
## 280 4.82     Label
## 281 4.84     Label
## 282 4.84     Label
## 283 4.84     Label
## 284 4.84     Label
## 285 4.89     Label
## 286 4.89     Label
## 287 4.89     Label
## 288 4.89     Label
## 289 4.89     Label
## 290 4.89     Label
## 291 4.89     Label
## 292 4.89     Label
## 293 4.95     Label
## 294 4.95     Label
## 295 4.95     Label
## 296 4.95     Label
## 297 4.96     Label
## 298 4.96     Label
## 299 4.96     Label
## 300 4.96     Label
## 301 2.01  No Label
## 302 2.01  No Label
## 303 2.01  No Label
## 304 2.01  No Label
## 305 2.03  No Label
## 306 2.03  No Label
## 307 2.03  No Label
## 308 2.03  No Label
## 309 2.07  No Label
## 310 2.07  No Label
## 311 2.07  No Label
## 312 2.07  No Label
## 313 2.25  No Label
## 314 2.25  No Label
## 315 2.25  No Label
## 316 2.25  No Label
## 317 2.50  No Label
## 318 2.50  No Label
## 319 2.50  No Label
## 320 2.50  No Label
## 321 2.59  No Label
## 322 2.59  No Label
## 323 2.59  No Label
## 324 2.59  No Label
## 325 2.71  No Label
## 326 2.71  No Label
## 327 2.71  No Label
## 328 2.71  No Label
## 329 2.88  No Label
## 330 2.88  No Label
## 331 2.88  No Label
## 332 2.88  No Label
## 333 2.90  No Label
## 334 2.90  No Label
## 335 2.90  No Label
## 336 2.90  No Label
## 337 2.93  No Label
## 338 2.93  No Label
## 339 2.93  No Label
## 340 2.93  No Label
## 341 2.99  No Label
## 342 2.99  No Label
## 343 2.99  No Label
## 344 2.99  No Label
## 345 3.02  No Label
## 346 3.02  No Label
## 347 3.02  No Label
## 348 3.02  No Label
## 349 3.02  No Label
## 350 3.02  No Label
## 351 3.02  No Label
## 352 3.02  No Label
## 353 3.06  No Label
## 354 3.06  No Label
## 355 3.06  No Label
## 356 3.06  No Label
## 357 3.06  No Label
## 358 3.06  No Label
## 359 3.06  No Label
## 360 3.06  No Label
## 361 3.18  No Label
## 362 3.18  No Label
## 363 3.18  No Label
## 364 3.18  No Label
## 365 3.27  No Label
## 366 3.27  No Label
## 367 3.27  No Label
## 368 3.27  No Label
## 369 3.27  No Label
## 370 3.27  No Label
## 371 3.27  No Label
## 372 3.27  No Label
## 373 3.33  No Label
## 374 3.33  No Label
## 375 3.33  No Label
## 376 3.33  No Label
## 377 3.41  No Label
## 378 3.41  No Label
## 379 3.41  No Label
## 380 3.41  No Label
## 381 3.41  No Label
## 382 3.45  No Label
## 383 3.45  No Label
## 384 3.45  No Label
## 385 3.45  No Label
## 386 3.50  No Label
## 387 3.50  No Label
## 388 3.50  No Label
## 389 3.50  No Label
## 390 3.54  No Label
## 391 3.54  No Label
## 392 3.54  No Label
## 393 3.54  No Label
## 394 3.71  No Label
## 395 3.71  No Label
## 396 3.71  No Label
## 397 3.71  No Label
## 398 3.76  No Label
## 399 3.76  No Label
## 400 3.76  No Label
## 401 3.76  No Label
## 402 3.82  No Label
## 403 3.82  No Label
## 404 3.82  No Label
## 405 3.83  No Label
## 406 3.83  No Label
## 407 3.83  No Label
## 408 3.83  No Label
## 409 3.93  No Label
## 410 3.93  No Label
## 411 3.94  No Label
## 412 3.94  No Label
## 413 4.02  No Label
## 414 4.02  No Label
## 415 4.02  No Label
## 416 4.02  No Label
## 417 4.02  No Label
## 418 4.02  No Label
## 419 4.02  No Label
## 420 4.02  No Label
## 421 4.07  No Label
## 422 4.07  No Label
## 423 4.07  No Label
## 424 4.07  No Label
## 425 4.09  No Label
## 426 4.09  No Label
## 427 4.09  No Label
## 428 4.09  No Label
## 429 4.25  No Label
## 430 4.25  No Label
## 431 4.25  No Label
## 432 4.25  No Label
## 433 4.32  No Label
## 434 4.32  No Label
## 435 4.32  No Label
## 436 4.32  No Label
## 437 4.37  No Label
## 438 4.37  No Label
## 439 4.37  No Label
## 440 4.37  No Label
## 441 4.39  No Label
## 442 4.39  No Label
## 443 4.39  No Label
## 444 4.39  No Label
## 445 4.41  No Label
## 446 4.41  No Label
## 447 4.41  No Label
## 448 4.41  No Label
## 449 4.41  No Label
## 450 4.41  No Label
## 451 4.41  No Label
## 452 4.41  No Label
## 453 4.42  No Label
## 454 4.42  No Label
## 455 4.42  No Label
## 456 4.42  No Label
## 457 4.44  No Label
## 458 4.44  No Label
## 459 4.44  No Label
## 460 4.44  No Label
## 461 4.47  No Label
## 462 4.47  No Label
## 463 4.47  No Label
## 464 4.47  No Label
## 465 4.47  No Label
## 466 4.47  No Label
## 467 4.47  No Label
## 468 4.47  No Label
## 469 4.52  No Label
## 470 4.52  No Label
## 471 4.52  No Label
## 472 4.52  No Label
## 473 4.55  No Label
## 474 4.55  No Label
## 475 4.55  No Label
## 476 4.55  No Label
## 477 4.58  No Label
## 478 4.58  No Label
## 479 4.58  No Label
## 480 4.58  No Label
## 481 4.61  No Label
## 482 4.61  No Label
## 483 4.61  No Label
## 484 4.61  No Label
## 485 4.61  No Label
## 486 4.61  No Label
## 487 4.61  No Label
## 488 4.61  No Label
## 489 4.75  No Label
## 490 4.75  No Label
## 491 4.75  No Label
## 492 4.75  No Label
## 493 4.76  No Label
## 494 4.76  No Label
## 495 4.76  No Label
## 496 4.76  No Label
## 497 4.79  No Label
## 498 4.79  No Label
## 499 4.79  No Label
## 500 4.79  No Label
## 501 4.82  No Label
## 502 4.82  No Label
## 503 4.82  No Label
## 504 4.82  No Label
## 505 4.82  No Label
## 506 4.82  No Label
## 507 4.82  No Label
## 508 4.82  No Label
## 509 3.50  No Label
## 510 3.50  No Label
## 511 3.50  No Label
## 512 3.50  No Label
## 513 3.24  No Label
## 514 3.24  No Label
## 515 3.24  No Label
## 516 3.24  No Label
## 517 3.94  No Label
## 518 3.94  No Label
## 519 3.94  No Label
## 520 3.94  No Label
## 521 2.72  No Label
## 522 2.72  No Label
## 523 2.72  No Label
## 524 2.72  No Label
## 525 2.31  No Label
## 526 2.31  No Label
## 527 2.31  No Label
## 528 2.31  No Label
## 529 3.14  No Label
## 530 3.14  No Label
## 531 3.14  No Label
## 532 3.14  No Label
## 533 3.72  No Label
## 534 3.72  No Label
## 535 3.72  No Label
## 536 3.72  No Label
## 537 3.10  No Label
## 538 3.10  No Label
## 539 3.10  No Label
## 540 3.10  No Label
## 541 2.34  No Label
## 542 2.34  No Label
## 543 2.34  No Label
## 544 2.34  No Label
## 545 3.67  No Label
## 546 3.67  No Label
## 547 3.67  No Label
## 548 3.66  No Label
## 549 2.58  No Label
## 550 2.58  No Label
## 551 2.58  No Label
## 552 2.58  No Label
## 553 2.55  No Label
## 554 2.55  No Label
## 555 2.55  No Label
## 556 2.55  No Label
## 557 2.43  No Label
## 558 2.43  No Label
## 559 2.43  No Label
## 560 2.43  No Label
## 561 2.70  No Label
## 562 2.70  No Label
## 563 2.70  No Label
## 564 2.70  No Label
## 565 2.76  No Label
## 566 2.76  No Label
## 567 2.76  No Label
## 568 2.76  No Label
## 569 2.84  No Label
## 570 2.84  No Label
## 571 2.84  No Label
## 572 2.84  No Label
## 573 2.46  No Label
## 574 2.46  No Label
## 575 2.46  No Label
## 576 2.46  No Label
## 577 2.37  No Label
## 578 2.37  No Label
## 579 2.37  No Label
## 580 2.37  No Label
## 581 2.83  No Label
## 582 2.83  No Label
## 583 2.83  No Label
## 584 2.83  No Label
## 585 2.69  No Label
## 586 2.69  No Label
## 587 2.69  No Label
## 588 2.69  No Label

3.1.1.2 Helper functions

The best part of select is that it has special helper function to perform common kinds of selection tasks.

starts_with

For example, let’s say we want all the variables that start with ‘c’. We can use the starts_with() helper function:

select(ps_data, starts_with("c"))
##     correct condition
## 1         1     Label
## 2         1     Label
## 3         0     Label
## 4         0     Label
## 5         0     Label
## 6         0     Label
## 7         1     Label
## 8         1     Label
## 9         0     Label
## 10        0     Label
## 11        0     Label
## 12        0     Label
## 13        0     Label
## 14        1     Label
## 15        1     Label
## 16        1     Label
## 17        0     Label
## 18        0     Label
## 19        1     Label
## 20        1     Label
## 21        1     Label
## 22        1     Label
## 23        0     Label
## 24        1     Label
## 25        1     Label
## 26        1     Label
## 27        1     Label
## 28        0     Label
## 29        1     Label
## 30        1     Label
## 31        0     Label
## 32        1     Label
## 33        1     Label
## 34        0     Label
## 35        1     Label
## 36        0     Label
## 37        0     Label
## 38        0     Label
## 39        1     Label
## 40        0     Label
## 41        1     Label
## 42        0     Label
## 43        1     Label
## 44        1     Label
## 45        1     Label
## 46        0     Label
## 47        0     Label
## 48        0     Label
## 49        0     Label
## 50        1     Label
## 51        0     Label
## 52        1     Label
## 53        1     Label
## 54        1     Label
## 55        0     Label
## 56        1     Label
## 57        1     Label
## 58        1     Label
## 59        0     Label
## 60        1     Label
## 61        0     Label
## 62        0     Label
## 63        1     Label
## 64        1     Label
## 65        0     Label
## 66        0     Label
## 67        1     Label
## 68        0     Label
## 69        0     Label
## 70        1     Label
## 71        1     Label
## 72        0     Label
## 73        1     Label
## 74        0     Label
## 75        1     Label
## 76        0     Label
## 77        0     Label
## 78        0     Label
## 79        1     Label
## 80        1     Label
## 81        1     Label
## 82        0     Label
## 83        1     Label
## 84        1     Label
## 85        1     Label
## 86        0     Label
## 87        0     Label
## 88        1     Label
## 89        1     Label
## 90        1     Label
## 91        1     Label
## 92        1     Label
## 93        1     Label
## 94        0     Label
## 95        1     Label
## 96        1     Label
## 97        0     Label
## 98        1     Label
## 99        1     Label
## 100       1     Label
## 101       1     Label
## 102       1     Label
## 103       1     Label
## 104       1     Label
## 105       1     Label
## 106       1     Label
## 107       1     Label
## 108       1     Label
## 109       1     Label
## 110       1     Label
## 111       0     Label
## 112       1     Label
## 113       0     Label
## 114       1     Label
## 115       0     Label
## 116       0     Label
## 117       0     Label
## 118       0     Label
## 119       1     Label
## 120       1     Label
## 121       1     Label
## 122       0     Label
## 123       0     Label
## 124       1     Label
## 125       1     Label
## 126       0     Label
## 127       1     Label
## 128       0     Label
## 129       0     Label
## 130       1     Label
## 131       1     Label
## 132       1     Label
## 133       1     Label
## 134       1     Label
## 135       1     Label
## 136       1     Label
## 137       0     Label
## 138       1     Label
## 139       1     Label
## 140       1     Label
## 141       0     Label
## 142       1     Label
## 143       1     Label
## 144       1     Label
## 145       0     Label
## 146       0     Label
## 147       1     Label
## 148       1     Label
## 149       0     Label
## 150       1     Label
## 151       1     Label
## 152       1     Label
## 153       0     Label
## 154       0     Label
## 155       0     Label
## 156       1     Label
## 157       1     Label
## 158       0     Label
## 159       1     Label
## 160       1     Label
## 161       0     Label
## 162       1     Label
## 163       0     Label
## 164       0     Label
## 165       1     Label
## 166       0     Label
## 167       1     Label
## 168       1     Label
## 169       1     Label
## 170       1     Label
## 171       1     Label
## 172       1     Label
## 173       0     Label
## 174       1     Label
## 175       1     Label
## 176       1     Label
## 177       1     Label
## 178       1     Label
## 179       1     Label
## 180       1     Label
## 181       1     Label
## 182       0     Label
## 183       1     Label
## 184       1     Label
## 185       1     Label
## 186       1     Label
## 187       1     Label
## 188       1     Label
## 189       1     Label
## 190       0     Label
## 191       0     Label
## 192       1     Label
## 193       0     Label
## 194       0     Label
## 195       1     Label
## 196       1     Label
## 197       1     Label
## 198       1     Label
## 199       1     Label
## 200       1     Label
## 201       1     Label
## 202       1     Label
## 203       1     Label
## 204       1     Label
## 205       0     Label
## 206       1     Label
## 207       1     Label
## 208       0     Label
## 209       1     Label
## 210       0     Label
## 211       0     Label
## 212       1     Label
## 213       1     Label
## 214       1     Label
## 215       1     Label
## 216       1     Label
## 217       1     Label
## 218       0     Label
## 219       0     Label
## 220       1     Label
## 221       1     Label
## 222       0     Label
## 223       1     Label
## 224       1     Label
## 225       1     Label
## 226       1     Label
## 227       1     Label
## 228       1     Label
## 229       1     Label
## 230       0     Label
## 231       1     Label
## 232       1     Label
## 233       1     Label
## 234       1     Label
## 235       1     Label
## 236       1     Label
## 237       1     Label
## 238       1     Label
## 239       0     Label
## 240       1     Label
## 241       0     Label
## 242       1     Label
## 243       0     Label
## 244       1     Label
## 245       1     Label
## 246       1     Label
## 247       1     Label
## 248       1     Label
## 249       1     Label
## 250       1     Label
## 251       0     Label
## 252       1     Label
## 253       1     Label
## 254       1     Label
## 255       1     Label
## 256       1     Label
## 257       1     Label
## 258       1     Label
## 259       1     Label
## 260       1     Label
## 261       0     Label
## 262       1     Label
## 263       1     Label
## 264       0     Label
## 265       0     Label
## 266       0     Label
## 267       1     Label
## 268       1     Label
## 269       1     Label
## 270       1     Label
## 271       1     Label
## 272       1     Label
## 273       1     Label
## 274       0     Label
## 275       1     Label
## 276       1     Label
## 277       1     Label
## 278       1     Label
## 279       1     Label
## 280       1     Label
## 281       0     Label
## 282       0     Label
## 283       0     Label
## 284       1     Label
## 285       1     Label
## 286       1     Label
## 287       1     Label
## 288       0     Label
## 289       1     Label
## 290       1     Label
## 291       1     Label
## 292       1     Label
## 293       0     Label
## 294       1     Label
## 295       1     Label
## 296       1     Label
## 297       1     Label
## 298       1     Label
## 299       1     Label
## 300       1     Label
## 301       1  No Label
## 302       0  No Label
## 303       1  No Label
## 304       0  No Label
## 305       0  No Label
## 306       0  No Label
## 307       0  No Label
## 308       0  No Label
## 309       0  No Label
## 310       0  No Label
## 311       0  No Label
## 312       0  No Label
## 313       0  No Label
## 314       0  No Label
## 315       0  No Label
## 316       0  No Label
## 317       0  No Label
## 318       1  No Label
## 319       0  No Label
## 320       1  No Label
## 321       0  No Label
## 322       0  No Label
## 323       1  No Label
## 324       0  No Label
## 325       0  No Label
## 326       0  No Label
## 327       0  No Label
## 328       0  No Label
## 329       0  No Label
## 330       0  No Label
## 331       0  No Label
## 332       0  No Label
## 333       0  No Label
## 334       0  No Label
## 335       0  No Label
## 336       1  No Label
## 337       1  No Label
## 338       0  No Label
## 339       0  No Label
## 340       0  No Label
## 341       1  No Label
## 342       1  No Label
## 343       0  No Label
## 344       0  No Label
## 345       0  No Label
## 346       0  No Label
## 347       0  No Label
## 348       0  No Label
## 349       0  No Label
## 350       1  No Label
## 351       0  No Label
## 352       1  No Label
## 353       0  No Label
## 354       0  No Label
## 355       0  No Label
## 356       0  No Label
## 357       0  No Label
## 358       0  No Label
## 359       0  No Label
## 360       0  No Label
## 361       0  No Label
## 362       0  No Label
## 363       0  No Label
## 364       0  No Label
## 365       0  No Label
## 366       1  No Label
## 367       0  No Label
## 368       1  No Label
## 369       1  No Label
## 370       0  No Label
## 371       0  No Label
## 372       0  No Label
## 373       0  No Label
## 374       0  No Label
## 375       1  No Label
## 376       1  No Label
## 377       0  No Label
## 378       0  No Label
## 379       0  No Label
## 380       0  No Label
## 381       0  No Label
## 382       0  No Label
## 383       0  No Label
## 384       0  No Label
## 385       0  No Label
## 386       0  No Label
## 387       1  No Label
## 388       0  No Label
## 389       0  No Label
## 390       0  No Label
## 391       1  No Label
## 392       1  No Label
## 393       0  No Label
## 394       0  No Label
## 395       0  No Label
## 396       0  No Label
## 397       0  No Label
## 398       0  No Label
## 399       0  No Label
## 400       1  No Label
## 401       0  No Label
## 402       1  No Label
## 403       1  No Label
## 404       1  No Label
## 405       0  No Label
## 406       0  No Label
## 407       0  No Label
## 408       0  No Label
## 409       1  No Label
## 410       0  No Label
## 411       0  No Label
## 412       0  No Label
## 413       0  No Label
## 414       0  No Label
## 415       0  No Label
## 416       0  No Label
## 417       0  No Label
## 418       0  No Label
## 419       0  No Label
## 420       1  No Label
## 421       0  No Label
## 422       0  No Label
## 423       1  No Label
## 424       0  No Label
## 425       0  No Label
## 426       0  No Label
## 427       1  No Label
## 428       0  No Label
## 429       0  No Label
## 430       0  No Label
## 431       1  No Label
## 432       0  No Label
## 433       0  No Label
## 434       0  No Label
## 435       0  No Label
## 436       1  No Label
## 437       0  No Label
## 438       0  No Label
## 439       0  No Label
## 440       0  No Label
## 441       0  No Label
## 442       0  No Label
## 443       0  No Label
## 444       0  No Label
## 445       0  No Label
## 446       0  No Label
## 447       0  No Label
## 448       0  No Label
## 449       1  No Label
## 450       0  No Label
## 451       0  No Label
## 452       0  No Label
## 453       1  No Label
## 454       0  No Label
## 455       0  No Label
## 456       0  No Label
## 457       0  No Label
## 458       0  No Label
## 459       1  No Label
## 460       0  No Label
## 461       0  No Label
## 462       0  No Label
## 463       0  No Label
## 464       0  No Label
## 465       0  No Label
## 466       0  No Label
## 467       1  No Label
## 468       0  No Label
## 469       0  No Label
## 470       0  No Label
## 471       0  No Label
## 472       0  No Label
## 473       0  No Label
## 474       0  No Label
## 475       0  No Label
## 476       1  No Label
## 477       0  No Label
## 478       0  No Label
## 479       0  No Label
## 480       1  No Label
## 481       0  No Label
## 482       0  No Label
## 483       0  No Label
## 484       0  No Label
## 485       0  No Label
## 486       0  No Label
## 487       0  No Label
## 488       0  No Label
## 489       0  No Label
## 490       0  No Label
## 491       0  No Label
## 492       0  No Label
## 493       0  No Label
## 494       0  No Label
## 495       0  No Label
## 496       0  No Label
## 497       0  No Label
## 498       0  No Label
## 499       0  No Label
## 500       1  No Label
## 501       0  No Label
## 502       0  No Label
## 503       0  No Label
## 504       0  No Label
## 505       0  No Label
## 506       0  No Label
## 507       0  No Label
## 508       0  No Label
## 509       0  No Label
## 510       0  No Label
## 511       1  No Label
## 512       0  No Label
## 513       0  No Label
## 514       1  No Label
## 515       0  No Label
## 516       1  No Label
## 517       0  No Label
## 518       0  No Label
## 519       0  No Label
## 520       0  No Label
## 521       0  No Label
## 522       1  No Label
## 523       1  No Label
## 524       0  No Label
## 525       0  No Label
## 526       0  No Label
## 527       0  No Label
## 528       1  No Label
## 529       1  No Label
## 530       1  No Label
## 531       1  No Label
## 532       0  No Label
## 533       1  No Label
## 534       1  No Label
## 535       0  No Label
## 536       0  No Label
## 537       0  No Label
## 538       0  No Label
## 539       0  No Label
## 540       0  No Label
## 541       1  No Label
## 542       0  No Label
## 543       0  No Label
## 544       1  No Label
## 545       0  No Label
## 546       0  No Label
## 547       0  No Label
## 548       0  No Label
## 549       0  No Label
## 550       0  No Label
## 551       0  No Label
## 552       0  No Label
## 553       0  No Label
## 554       0  No Label
## 555       0  No Label
## 556       1  No Label
## 557       0  No Label
## 558       0  No Label
## 559       0  No Label
## 560       1  No Label
## 561       0  No Label
## 562       1  No Label
## 563       0  No Label
## 564       1  No Label
## 565       0  No Label
## 566       0  No Label
## 567       0  No Label
## 568       0  No Label
## 569       1  No Label
## 570       0  No Label
## 571       0  No Label
## 572       0  No Label
## 573       1  No Label
## 574       0  No Label
## 575       1  No Label
## 576       0  No Label
## 577       0  No Label
## 578       0  No Label
## 579       1  No Label
## 580       0  No Label
## 581       0  No Label
## 582       0  No Label
## 583       1  No Label
## 584       0  No Label
## 585       0  No Label
## 586       0  No Label
## 587       0  No Label
## 588       0  No Label

That is way simpler than the base R solution we discussed above, which was

ps_data[, grep("^c", colnames(ps_data))]
##     correct condition
## 1         1     Label
## 2         1     Label
## 3         0     Label
## 4         0     Label
## 5         0     Label
## 6         0     Label
## 7         1     Label
## 8         1     Label
## 9         0     Label
## 10        0     Label
## 11        0     Label
## 12        0     Label
## 13        0     Label
## 14        1     Label
## 15        1     Label
## 16        1     Label
## 17        0     Label
## 18        0     Label
## 19        1     Label
## 20        1     Label
## 21        1     Label
## 22        1     Label
## 23        0     Label
## 24        1     Label
## 25        1     Label
## 26        1     Label
## 27        1     Label
## 28        0     Label
## 29        1     Label
## 30        1     Label
## 31        0     Label
## 32        1     Label
## 33        1     Label
## 34        0     Label
## 35        1     Label
## 36        0     Label
## 37        0     Label
## 38        0     Label
## 39        1     Label
## 40        0     Label
## 41        1     Label
## 42        0     Label
## 43        1     Label
## 44        1     Label
## 45        1     Label
## 46        0     Label
## 47        0     Label
## 48        0     Label
## 49        0     Label
## 50        1     Label
## 51        0     Label
## 52        1     Label
## 53        1     Label
## 54        1     Label
## 55        0     Label
## 56        1     Label
## 57        1     Label
## 58        1     Label
## 59        0     Label
## 60        1     Label
## 61        0     Label
## 62        0     Label
## 63        1     Label
## 64        1     Label
## 65        0     Label
## 66        0     Label
## 67        1     Label
## 68        0     Label
## 69        0     Label
## 70        1     Label
## 71        1     Label
## 72        0     Label
## 73        1     Label
## 74        0     Label
## 75        1     Label
## 76        0     Label
## 77        0     Label
## 78        0     Label
## 79        1     Label
## 80        1     Label
## 81        1     Label
## 82        0     Label
## 83        1     Label
## 84        1     Label
## 85        1     Label
## 86        0     Label
## 87        0     Label
## 88        1     Label
## 89        1     Label
## 90        1     Label
## 91        1     Label
## 92        1     Label
## 93        1     Label
## 94        0     Label
## 95        1     Label
## 96        1     Label
## 97        0     Label
## 98        1     Label
## 99        1     Label
## 100       1     Label
## 101       1     Label
## 102       1     Label
## 103       1     Label
## 104       1     Label
## 105       1     Label
## 106       1     Label
## 107       1     Label
## 108       1     Label
## 109       1     Label
## 110       1     Label
## 111       0     Label
## 112       1     Label
## 113       0     Label
## 114       1     Label
## 115       0     Label
## 116       0     Label
## 117       0     Label
## 118       0     Label
## 119       1     Label
## 120       1     Label
## 121       1     Label
## 122       0     Label
## 123       0     Label
## 124       1     Label
## 125       1     Label
## 126       0     Label
## 127       1     Label
## 128       0     Label
## 129       0     Label
## 130       1     Label
## 131       1     Label
## 132       1     Label
## 133       1     Label
## 134       1     Label
## 135       1     Label
## 136       1     Label
## 137       0     Label
## 138       1     Label
## 139       1     Label
## 140       1     Label
## 141       0     Label
## 142       1     Label
## 143       1     Label
## 144       1     Label
## 145       0     Label
## 146       0     Label
## 147       1     Label
## 148       1     Label
## 149       0     Label
## 150       1     Label
## 151       1     Label
## 152       1     Label
## 153       0     Label
## 154       0     Label
## 155       0     Label
## 156       1     Label
## 157       1     Label
## 158       0     Label
## 159       1     Label
## 160       1     Label
## 161       0     Label
## 162       1     Label
## 163       0     Label
## 164       0     Label
## 165       1     Label
## 166       0     Label
## 167       1     Label
## 168       1     Label
## 169       1     Label
## 170       1     Label
## 171       1     Label
## 172       1     Label
## 173       0     Label
## 174       1     Label
## 175       1     Label
## 176       1     Label
## 177       1     Label
## 178       1     Label
## 179       1     Label
## 180       1     Label
## 181       1     Label
## 182       0     Label
## 183       1     Label
## 184       1     Label
## 185       1     Label
## 186       1     Label
## 187       1     Label
## 188       1     Label
## 189       1     Label
## 190       0     Label
## 191       0     Label
## 192       1     Label
## 193       0     Label
## 194       0     Label
## 195       1     Label
## 196       1     Label
## 197       1     Label
## 198       1     Label
## 199       1     Label
## 200       1     Label
## 201       1     Label
## 202       1     Label
## 203       1     Label
## 204       1     Label
## 205       0     Label
## 206       1     Label
## 207       1     Label
## 208       0     Label
## 209       1     Label
## 210       0     Label
## 211       0     Label
## 212       1     Label
## 213       1     Label
## 214       1     Label
## 215       1     Label
## 216       1     Label
## 217       1     Label
## 218       0     Label
## 219       0     Label
## 220       1     Label
## 221       1     Label
## 222       0     Label
## 223       1     Label
## 224       1     Label
## 225       1     Label
## 226       1     Label
## 227       1     Label
## 228       1     Label
## 229       1     Label
## 230       0     Label
## 231       1     Label
## 232       1     Label
## 233       1     Label
## 234       1     Label
## 235       1     Label
## 236       1     Label
## 237       1     Label
## 238       1     Label
## 239       0     Label
## 240       1     Label
## 241       0     Label
## 242       1     Label
## 243       0     Label
## 244       1     Label
## 245       1     Label
## 246       1     Label
## 247       1     Label
## 248       1     Label
## 249       1     Label
## 250       1     Label
## 251       0     Label
## 252       1     Label
## 253       1     Label
## 254       1     Label
## 255       1     Label
## 256       1     Label
## 257       1     Label
## 258       1     Label
## 259       1     Label
## 260       1     Label
## 261       0     Label
## 262       1     Label
## 263       1     Label
## 264       0     Label
## 265       0     Label
## 266       0     Label
## 267       1     Label
## 268       1     Label
## 269       1     Label
## 270       1     Label
## 271       1     Label
## 272       1     Label
## 273       1     Label
## 274       0     Label
## 275       1     Label
## 276       1     Label
## 277       1     Label
## 278       1     Label
## 279       1     Label
## 280       1     Label
## 281       0     Label
## 282       0     Label
## 283       0     Label
## 284       1     Label
## 285       1     Label
## 286       1     Label
## 287       1     Label
## 288       0     Label
## 289       1     Label
## 290       1     Label
## 291       1     Label
## 292       1     Label
## 293       0     Label
## 294       1     Label
## 295       1     Label
## 296       1     Label
## 297       1     Label
## 298       1     Label
## 299       1     Label
## 300       1     Label
## 301       1  No Label
## 302       0  No Label
## 303       1  No Label
## 304       0  No Label
## 305       0  No Label
## 306       0  No Label
## 307       0  No Label
## 308       0  No Label
## 309       0  No Label
## 310       0  No Label
## 311       0  No Label
## 312       0  No Label
## 313       0  No Label
## 314       0  No Label
## 315       0  No Label
## 316       0  No Label
## 317       0  No Label
## 318       1  No Label
## 319       0  No Label
## 320       1  No Label
## 321       0  No Label
## 322       0  No Label
## 323       1  No Label
## 324       0  No Label
## 325       0  No Label
## 326       0  No Label
## 327       0  No Label
## 328       0  No Label
## 329       0  No Label
## 330       0  No Label
## 331       0  No Label
## 332       0  No Label
## 333       0  No Label
## 334       0  No Label
## 335       0  No Label
## 336       1  No Label
## 337       1  No Label
## 338       0  No Label
## 339       0  No Label
## 340       0  No Label
## 341       1  No Label
## 342       1  No Label
## 343       0  No Label
## 344       0  No Label
## 345       0  No Label
## 346       0  No Label
## 347       0  No Label
## 348       0  No Label
## 349       0  No Label
## 350       1  No Label
## 351       0  No Label
## 352       1  No Label
## 353       0  No Label
## 354       0  No Label
## 355       0  No Label
## 356       0  No Label
## 357       0  No Label
## 358       0  No Label
## 359       0  No Label
## 360       0  No Label
## 361       0  No Label
## 362       0  No Label
## 363       0  No Label
## 364       0  No Label
## 365       0  No Label
## 366       1  No Label
## 367       0  No Label
## 368       1  No Label
## 369       1  No Label
## 370       0  No Label
## 371       0  No Label
## 372       0  No Label
## 373       0  No Label
## 374       0  No Label
## 375       1  No Label
## 376       1  No Label
## 377       0  No Label
## 378       0  No Label
## 379       0  No Label
## 380       0  No Label
## 381       0  No Label
## 382       0  No Label
## 383       0  No Label
## 384       0  No Label
## 385       0  No Label
## 386       0  No Label
## 387       1  No Label
## 388       0  No Label
## 389       0  No Label
## 390       0  No Label
## 391       1  No Label
## 392       1  No Label
## 393       0  No Label
## 394       0  No Label
## 395       0  No Label
## 396       0  No Label
## 397       0  No Label
## 398       0  No Label
## 399       0  No Label
## 400       1  No Label
## 401       0  No Label
## 402       1  No Label
## 403       1  No Label
## 404       1  No Label
## 405       0  No Label
## 406       0  No Label
## 407       0  No Label
## 408       0  No Label
## 409       1  No Label
## 410       0  No Label
## 411       0  No Label
## 412       0  No Label
## 413       0  No Label
## 414       0  No Label
## 415       0  No Label
## 416       0  No Label
## 417       0  No Label
## 418       0  No Label
## 419       0  No Label
## 420       1  No Label
## 421       0  No Label
## 422       0  No Label
## 423       1  No Label
## 424       0  No Label
## 425       0  No Label
## 426       0  No Label
## 427       1  No Label
## 428       0  No Label
## 429       0  No Label
## 430       0  No Label
## 431       1  No Label
## 432       0  No Label
## 433       0  No Label
## 434       0  No Label
## 435       0  No Label
## 436       1  No Label
## 437       0  No Label
## 438       0  No Label
## 439       0  No Label
## 440       0  No Label
## 441       0  No Label
## 442       0  No Label
## 443       0  No Label
## 444       0  No Label
## 445       0  No Label
## 446       0  No Label
## 447       0  No Label
## 448       0  No Label
## 449       1  No Label
## 450       0  No Label
## 451       0  No Label
## 452       0  No Label
## 453       1  No Label
## 454       0  No Label
## 455       0  No Label
## 456       0  No Label
## 457       0  No Label
## 458       0  No Label
## 459       1  No Label
## 460       0  No Label
## 461       0  No Label
## 462       0  No Label
## 463       0  No Label
## 464       0  No Label
## 465       0  No Label
## 466       0  No Label
## 467       1  No Label
## 468       0  No Label
## 469       0  No Label
## 470       0  No Label
## 471       0  No Label
## 472       0  No Label
## 473       0  No Label
## 474       0  No Label
## 475       0  No Label
## 476       1  No Label
## 477       0  No Label
## 478       0  No Label
## 479       0  No Label
## 480       1  No Label
## 481       0  No Label
## 482       0  No Label
## 483       0  No Label
## 484       0  No Label
## 485       0  No Label
## 486       0  No Label
## 487       0  No Label
## 488       0  No Label
## 489       0  No Label
## 490       0  No Label
## 491       0  No Label
## 492       0  No Label
## 493       0  No Label
## 494       0  No Label
## 495       0  No Label
## 496       0  No Label
## 497       0  No Label
## 498       0  No Label
## 499       0  No Label
## 500       1  No Label
## 501       0  No Label
## 502       0  No Label
## 503       0  No Label
## 504       0  No Label
## 505       0  No Label
## 506       0  No Label
## 507       0  No Label
## 508       0  No Label
## 509       0  No Label
## 510       0  No Label
## 511       1  No Label
## 512       0  No Label
## 513       0  No Label
## 514       1  No Label
## 515       0  No Label
## 516       1  No Label
## 517       0  No Label
## 518       0  No Label
## 519       0  No Label
## 520       0  No Label
## 521       0  No Label
## 522       1  No Label
## 523       1  No Label
## 524       0  No Label
## 525       0  No Label
## 526       0  No Label
## 527       0  No Label
## 528       1  No Label
## 529       1  No Label
## 530       1  No Label
## 531       1  No Label
## 532       0  No Label
## 533       1  No Label
## 534       1  No Label
## 535       0  No Label
## 536       0  No Label
## 537       0  No Label
## 538       0  No Label
## 539       0  No Label
## 540       0  No Label
## 541       1  No Label
## 542       0  No Label
## 543       0  No Label
## 544       1  No Label
## 545       0  No Label
## 546       0  No Label
## 547       0  No Label
## 548       0  No Label
## 549       0  No Label
## 550       0  No Label
## 551       0  No Label
## 552       0  No Label
## 553       0  No Label
## 554       0  No Label
## 555       0  No Label
## 556       1  No Label
## 557       0  No Label
## 558       0  No Label
## 559       0  No Label
## 560       1  No Label
## 561       0  No Label
## 562       1  No Label
## 563       0  No Label
## 564       1  No Label
## 565       0  No Label
## 566       0  No Label
## 567       0  No Label
## 568       0  No Label
## 569       1  No Label
## 570       0  No Label
## 571       0  No Label
## 572       0  No Label
## 573       1  No Label
## 574       0  No Label
## 575       1  No Label
## 576       0  No Label
## 577       0  No Label
## 578       0  No Label
## 579       1  No Label
## 580       0  No Label
## 581       0  No Label
## 582       0  No Label
## 583       1  No Label
## 584       0  No Label
## 585       0  No Label
## 586       0  No Label
## 587       0  No Label
## 588       0  No Label

ends_with

Select columns that end with some character:

select(ps_data, ends_with("e"))
##      age
## 1   2.00
## 2   2.00
## 3   2.00
## 4   2.00
## 5   2.13
## 6   2.13
## 7   2.13
## 8   2.13
## 9   2.32
## 10  2.32
## 11  2.32
## 12  2.32
## 13  2.38
## 14  2.38
## 15  2.38
## 16  2.38
## 17  2.47
## 18  2.47
## 19  2.47
## 20  2.47
## 21  2.50
## 22  2.50
## 23  2.50
## 24  2.50
## 25  2.58
## 26  2.58
## 27  2.58
## 28  2.58
## 29  2.59
## 30  2.59
## 31  2.59
## 32  2.59
## 33  2.61
## 34  2.61
## 35  2.61
## 36  2.61
## 37  2.72
## 38  2.72
## 39  2.72
## 40  2.72
## 41  2.73
## 42  2.73
## 43  2.73
## 44  2.73
## 45  2.74
## 46  2.74
## 47  2.74
## 48  2.74
## 49  2.79
## 50  2.79
## 51  2.79
## 52  2.79
## 53  2.80
## 54  2.80
## 55  2.80
## 56  2.80
## 57  2.83
## 58  2.83
## 59  2.83
## 60  2.83
## 61  2.83
## 62  2.83
## 63  2.83
## 64  2.83
## 65  2.85
## 66  2.85
## 67  2.85
## 68  2.85
## 69  2.88
## 70  2.88
## 71  2.88
## 72  2.88
## 73  2.88
## 74  2.88
## 75  2.88
## 76  2.88
## 77  2.89
## 78  2.89
## 79  2.89
## 80  2.89
## 81  2.91
## 82  2.91
## 83  2.91
## 84  2.91
## 85  2.95
## 86  2.95
## 87  2.95
## 88  2.95
## 89  2.98
## 90  2.98
## 91  2.98
## 92  2.98
## 93  2.99
## 94  2.99
## 95  2.99
## 96  2.99
## 97  3.00
## 98  3.00
## 99  3.00
## 100 3.00
## 101 3.09
## 102 3.09
## 103 3.09
## 104 3.09
## 105 3.10
## 106 3.10
## 107 3.10
## 108 3.10
## 109 3.19
## 110 3.19
## 111 3.19
## 112 3.19
## 113 3.20
## 114 3.20
## 115 3.20
## 116 3.20
## 117 3.22
## 118 3.22
## 119 3.22
## 120 3.22
## 121 3.24
## 122 3.24
## 123 3.24
## 124 3.24
## 125 3.25
## 126 3.25
## 127 3.25
## 128 3.25
## 129 3.26
## 130 3.26
## 131 3.26
## 132 3.26
## 133 3.28
## 134 3.28
## 135 3.28
## 136 3.28
## 137 3.30
## 138 3.30
## 139 3.30
## 140 3.30
## 141 3.46
## 142 3.46
## 143 3.46
## 144 3.46
## 145 3.46
## 146 3.46
## 147 3.46
## 148 3.46
## 149 3.46
## 150 3.46
## 151 3.46
## 152 3.46
## 153 3.50
## 154 3.50
## 155 3.50
## 156 3.50
## 157 3.52
## 158 3.52
## 159 3.52
## 160 3.52
## 161 3.55
## 162 3.55
## 163 3.55
## 164 3.55
## 165 3.56
## 166 3.56
## 167 3.56
## 168 3.56
## 169 3.59
## 170 3.59
## 171 3.59
## 172 3.59
## 173 3.72
## 174 3.72
## 175 3.72
## 176 3.72
## 177 3.75
## 178 3.75
## 179 3.75
## 180 3.75
## 181 3.82
## 182 3.82
## 183 3.82
## 184 3.82
## 185 3.82
## 186 3.82
## 187 3.82
## 188 3.82
## 189 3.85
## 190 3.85
## 191 3.85
## 192 3.85
## 193 3.92
## 194 3.92
## 195 3.92
## 196 3.92
## 197 3.92
## 198 3.92
## 199 3.92
## 200 3.92
## 201 3.96
## 202 3.96
## 203 3.96
## 204 3.96
## 205 4.50
## 206 4.50
## 207 4.50
## 208 4.50
## 209 4.14
## 210 4.14
## 211 4.14
## 212 4.14
## 213 4.16
## 214 4.16
## 215 4.16
## 216 4.16
## 217 4.16
## 218 4.16
## 219 4.16
## 220 4.16
## 221 4.22
## 222 4.22
## 223 4.22
## 224 4.22
## 225 4.26
## 226 4.26
## 227 4.26
## 228 4.26
## 229 4.28
## 230 4.28
## 231 4.28
## 232 4.28
## 233 4.29
## 234 4.29
## 235 4.29
## 236 4.29
## 237 4.33
## 238 4.33
## 239 4.33
## 240 4.33
## 241 4.38
## 242 4.38
## 243 4.38
## 244 4.38
## 245 4.55
## 246 4.55
## 247 4.55
## 248 4.55
## 249 4.57
## 250 4.57
## 251 4.57
## 252 4.57
## 253 4.58
## 254 4.58
## 255 4.58
## 256 4.58
## 257 4.60
## 258 4.60
## 259 4.60
## 260 4.60
## 261 4.62
## 262 4.62
## 263 4.62
## 264 4.62
## 265 4.64
## 266 4.64
## 267 4.64
## 268 4.64
## 269 4.64
## 270 4.64
## 271 4.64
## 272 4.64
## 273 4.73
## 274 4.73
## 275 4.73
## 276 4.73
## 277 4.82
## 278 4.82
## 279 4.82
## 280 4.82
## 281 4.84
## 282 4.84
## 283 4.84
## 284 4.84
## 285 4.89
## 286 4.89
## 287 4.89
## 288 4.89
## 289 4.89
## 290 4.89
## 291 4.89
## 292 4.89
## 293 4.95
## 294 4.95
## 295 4.95
## 296 4.95
## 297 4.96
## 298 4.96
## 299 4.96
## 300 4.96
## 301 2.01
## 302 2.01
## 303 2.01
## 304 2.01
## 305 2.03
## 306 2.03
## 307 2.03
## 308 2.03
## 309 2.07
## 310 2.07
## 311 2.07
## 312 2.07
## 313 2.25
## 314 2.25
## 315 2.25
## 316 2.25
## 317 2.50
## 318 2.50
## 319 2.50
## 320 2.50
## 321 2.59
## 322 2.59
## 323 2.59
## 324 2.59
## 325 2.71
## 326 2.71
## 327 2.71
## 328 2.71
## 329 2.88
## 330 2.88
## 331 2.88
## 332 2.88
## 333 2.90
## 334 2.90
## 335 2.90
## 336 2.90
## 337 2.93
## 338 2.93
## 339 2.93
## 340 2.93
## 341 2.99
## 342 2.99
## 343 2.99
## 344 2.99
## 345 3.02
## 346 3.02
## 347 3.02
## 348 3.02
## 349 3.02
## 350 3.02
## 351 3.02
## 352 3.02
## 353 3.06
## 354 3.06
## 355 3.06
## 356 3.06
## 357 3.06
## 358 3.06
## 359 3.06
## 360 3.06
## 361 3.18
## 362 3.18
## 363 3.18
## 364 3.18
## 365 3.27
## 366 3.27
## 367 3.27
## 368 3.27
## 369 3.27
## 370 3.27
## 371 3.27
## 372 3.27
## 373 3.33
## 374 3.33
## 375 3.33
## 376 3.33
## 377 3.41
## 378 3.41
## 379 3.41
## 380 3.41
## 381 3.41
## 382 3.45
## 383 3.45
## 384 3.45
## 385 3.45
## 386 3.50
## 387 3.50
## 388 3.50
## 389 3.50
## 390 3.54
## 391 3.54
## 392 3.54
## 393 3.54
## 394 3.71
## 395 3.71
## 396 3.71
## 397 3.71
## 398 3.76
## 399 3.76
## 400 3.76
## 401 3.76
## 402 3.82
## 403 3.82
## 404 3.82
## 405 3.83
## 406 3.83
## 407 3.83
## 408 3.83
## 409 3.93
## 410 3.93
## 411 3.94
## 412 3.94
## 413 4.02
## 414 4.02
## 415 4.02
## 416 4.02
## 417 4.02
## 418 4.02
## 419 4.02
## 420 4.02
## 421 4.07
## 422 4.07
## 423 4.07
## 424 4.07
## 425 4.09
## 426 4.09
## 427 4.09
## 428 4.09
## 429 4.25
## 430 4.25
## 431 4.25
## 432 4.25
## 433 4.32
## 434 4.32
## 435 4.32
## 436 4.32
## 437 4.37
## 438 4.37
## 439 4.37
## 440 4.37
## 441 4.39
## 442 4.39
## 443 4.39
## 444 4.39
## 445 4.41
## 446 4.41
## 447 4.41
## 448 4.41
## 449 4.41
## 450 4.41
## 451 4.41
## 452 4.41
## 453 4.42
## 454 4.42
## 455 4.42
## 456 4.42
## 457 4.44
## 458 4.44
## 459 4.44
## 460 4.44
## 461 4.47
## 462 4.47
## 463 4.47
## 464 4.47
## 465 4.47
## 466 4.47
## 467 4.47
## 468 4.47
## 469 4.52
## 470 4.52
## 471 4.52
## 472 4.52
## 473 4.55
## 474 4.55
## 475 4.55
## 476 4.55
## 477 4.58
## 478 4.58
## 479 4.58
## 480 4.58
## 481 4.61
## 482 4.61
## 483 4.61
## 484 4.61
## 485 4.61
## 486 4.61
## 487 4.61
## 488 4.61
## 489 4.75
## 490 4.75
## 491 4.75
## 492 4.75
## 493 4.76
## 494 4.76
## 495 4.76
## 496 4.76
## 497 4.79
## 498 4.79
## 499 4.79
## 500 4.79
## 501 4.82
## 502 4.82
## 503 4.82
## 504 4.82
## 505 4.82
## 506 4.82
## 507 4.82
## 508 4.82
## 509 3.50
## 510 3.50
## 511 3.50
## 512 3.50
## 513 3.24
## 514 3.24
## 515 3.24
## 516 3.24
## 517 3.94
## 518 3.94
## 519 3.94
## 520 3.94
## 521 2.72
## 522 2.72
## 523 2.72
## 524 2.72
## 525 2.31
## 526 2.31
## 527 2.31
## 528 2.31
## 529 3.14
## 530 3.14
## 531 3.14
## 532 3.14
## 533 3.72
## 534 3.72
## 535 3.72
## 536 3.72
## 537 3.10
## 538 3.10
## 539 3.10
## 540 3.10
## 541 2.34
## 542 2.34
## 543 2.34
## 544 2.34
## 545 3.67
## 546 3.67
## 547 3.67
## 548 3.66
## 549 2.58
## 550 2.58
## 551 2.58
## 552 2.58
## 553 2.55
## 554 2.55
## 555 2.55
## 556 2.55
## 557 2.43
## 558 2.43
## 559 2.43
## 560 2.43
## 561 2.70
## 562 2.70
## 563 2.70
## 564 2.70
## 565 2.76
## 566 2.76
## 567 2.76
## 568 2.76
## 569 2.84
## 570 2.84
## 571 2.84
## 572 2.84
## 573 2.46
## 574 2.46
## 575 2.46
## 576 2.46
## 577 2.37
## 578 2.37
## 579 2.37
## 580 2.37
## 581 2.83
## 582 2.83
## 583 2.83
## 584 2.83
## 585 2.69
## 586 2.69
## 587 2.69
## 588 2.69

contains

Select columns that contain a character.

select(ps_data, contains("i"))
##      subid   item condition
## 1      M22  faces     Label
## 2      M22 houses     Label
## 3      M22  pasta     Label
## 4      M22   beds     Label
## 5      T22   beds     Label
## 6      T22  faces     Label
## 7      T22 houses     Label
## 8      T22  pasta     Label
## 9      T17  pasta     Label
## 10     T17  faces     Label
## 11     T17 houses     Label
## 12     T17   beds     Label
## 13      M3  faces     Label
## 14      M3 houses     Label
## 15      M3  pasta     Label
## 16      M3   beds     Label
## 17     T19  faces     Label
## 18     T19 houses     Label
## 19     T19  pasta     Label
## 20     T19   beds     Label
## 21     T20  faces     Label
## 22     T20 houses     Label
## 23     T20  pasta     Label
## 24     T20   beds     Label
## 25     T21  faces     Label
## 26     T21 houses     Label
## 27     T21  pasta     Label
## 28     T21   beds     Label
## 29     M26  faces     Label
## 30     M26 houses     Label
## 31     M26  pasta     Label
## 32     M26   beds     Label
## 33     T18  faces     Label
## 34     T18 houses     Label
## 35     T18  pasta     Label
## 36     T18   beds     Label
## 37     T12   beds     Label
## 38     T12  faces     Label
## 39     T12 houses     Label
## 40     T12  pasta     Label
## 41     T16  faces     Label
## 42     T16 houses     Label
## 43     T16  pasta     Label
## 44     T16   beds     Label
## 45      T7  faces     Label
## 46      T7 houses     Label
## 47      T7  pasta     Label
## 48      T7   beds     Label
## 49      T9 houses     Label
## 50      T9  faces     Label
## 51      T9  pasta     Label
## 52      T9   beds     Label
## 53      T5  faces     Label
## 54      T5 houses     Label
## 55      T5  pasta     Label
## 56      T5   beds     Label
## 57     T14  faces     Label
## 58     T14 houses     Label
## 59     T14  pasta     Label
## 60     T14   beds     Label
## 61      T2 houses     Label
## 62      T2  faces     Label
## 63      T2  pasta     Label
## 64      T2   beds     Label
## 65     T15  faces     Label
## 66     T15 houses     Label
## 67     T15  pasta     Label
## 68     T15   beds     Label
## 69     M13 houses     Label
## 70     M13   beds     Label
## 71     M13  faces     Label
## 72     M13  pasta     Label
## 73     M12  faces     Label
## 74     M12 houses     Label
## 75     M12  pasta     Label
## 76     M12   beds     Label
## 77     T13   beds     Label
## 78     T13  faces     Label
## 79     T13 houses     Label
## 80     T13  pasta     Label
## 81      T8  faces     Label
## 82      T8 houses     Label
## 83      T8  pasta     Label
## 84      T8   beds     Label
## 85      T1  faces     Label
## 86      T1 houses     Label
## 87      T1  pasta     Label
## 88      T1   beds     Label
## 89     M15  faces     Label
## 90     M15 houses     Label
## 91     M15  pasta     Label
## 92     M15   beds     Label
## 93     T11  faces     Label
## 94     T11 houses     Label
## 95     T11  pasta     Label
## 96     T11   beds     Label
## 97     T10  faces     Label
## 98     T10 houses     Label
## 99     T10  pasta     Label
## 100    T10   beds     Label
## 101     T3  faces     Label
## 102     T3 houses     Label
## 103     T3  pasta     Label
## 104     T3   beds     Label
## 105     T6  faces     Label
## 106     T6 houses     Label
## 107     T6  pasta     Label
## 108     T6   beds     Label
## 109    M32   beds     Label
## 110    M32  faces     Label
## 111    M32 houses     Label
## 112    M32  pasta     Label
## 113     M1  faces     Label
## 114     M1   beds     Label
## 115     M1  pasta     Label
## 116     M1 houses     Label
## 117    C16  faces     Label
## 118    C16 houses     Label
## 119    C16  pasta     Label
## 120    C16   beds     Label
## 121     T4  faces     Label
## 122     T4 houses     Label
## 123     T4  pasta     Label
## 124     T4   beds     Label
## 125    C17  faces     Label
## 126    C17 houses     Label
## 127    C17  pasta     Label
## 128    C17   beds     Label
## 129     C6  faces     Label
## 130     C6 houses     Label
## 131     C6  pasta     Label
## 132     C6   beds     Label
## 133    M10  faces     Label
## 134    M10 houses     Label
## 135    M10   beds     Label
## 136    M10  pasta     Label
## 137    M31  faces     Label
## 138    M31 houses     Label
## 139    M31  pasta     Label
## 140    M31   beds     Label
## 141     C3 houses     Label
## 142     C3  pasta     Label
## 143     C3   beds     Label
## 144     C3  faces     Label
## 145    C10  faces     Label
## 146    C10 houses     Label
## 147    C10  pasta     Label
## 148    C10   beds     Label
## 149    M18  faces     Label
## 150    M18 houses     Label
## 151    M18  pasta     Label
## 152    M18   beds     Label
## 153    M16  faces     Label
## 154    M16 houses     Label
## 155    M16  pasta     Label
## 156    M16   beds     Label
## 157    M23  faces     Label
## 158    M23 houses     Label
## 159    M23  pasta     Label
## 160    M23   beds     Label
## 161     C7  faces     Label
## 162     C7 houses     Label
## 163     C7  pasta     Label
## 164     C7   beds     Label
## 165    C12  faces     Label
## 166    C12 houses     Label
## 167    C12  pasta     Label
## 168    C12   beds     Label
## 169    C15  faces     Label
## 170    C15 houses     Label
## 171    C15  pasta     Label
## 172    C15   beds     Label
## 173    M29  faces     Label
## 174    M29 houses     Label
## 175    M29  pasta     Label
## 176    M29   beds     Label
## 177    C20  faces     Label
## 178    C20 houses     Label
## 179    C20  pasta     Label
## 180    C20   beds     Label
## 181    M11  faces     Label
## 182    M11 houses     Label
## 183    M11  pasta     Label
## 184    M11   beds     Label
## 185     C9   beds     Label
## 186     C9  faces     Label
## 187     C9 houses     Label
## 188     C9  pasta     Label
## 189    C24  faces     Label
## 190    C24 houses     Label
## 191    C24  pasta     Label
## 192    C24   beds     Label
## 193    C22  faces     Label
## 194    C22 houses     Label
## 195    C22  pasta     Label
## 196    C22   beds     Label
## 197     C8  faces     Label
## 198     C8 houses     Label
## 199     C8  pasta     Label
## 200     C8   beds     Label
## 201     M4  faces     Label
## 202     M4 houses     Label
## 203     M4  pasta     Label
## 204     M4   beds     Label
## 205     M6  faces     Label
## 206     M6 houses     Label
## 207     M6  pasta     Label
## 208     M6   beds     Label
## 209    C19  faces     Label
## 210    C19 houses     Label
## 211    C19  pasta     Label
## 212    C19   beds     Label
## 213     C1  faces     Label
## 214     C1 houses     Label
## 215     C1  pasta     Label
## 216     C1   beds     Label
## 217    M19   beds     Label
## 218    M19  faces     Label
## 219    M19 houses     Label
## 220    M19  pasta     Label
## 221    C11  faces     Label
## 222    C11 houses     Label
## 223    C11  pasta     Label
## 224    C11   beds     Label
## 225     M9  faces     Label
## 226     M9 houses     Label
## 227     M9  pasta     Label
## 228     M9   beds     Label
## 229     M2  faces     Label
## 230     M2 houses     Label
## 231     M2  pasta     Label
## 232     M2   beds     Label
## 233     C5  faces     Label
## 234     C5 houses     Label
## 235     C5  pasta     Label
## 236     C5   beds     Label
## 237    M30   beds     Label
## 238    M30  faces     Label
## 239    M30 houses     Label
## 240    M30  pasta     Label
## 241    C13  faces     Label
## 242    C13 houses     Label
## 243    C13  pasta     Label
## 244    C13   beds     Label
## 245     C4  faces     Label
## 246     C4 houses     Label
## 247     C4  pasta     Label
## 248     C4   beds     Label
## 249    C14  faces     Label
## 250    C14 houses     Label
## 251    C14  pasta     Label
## 252    C14   beds     Label
## 253    M17  faces     Label
## 254    M17 houses     Label
## 255    M17  pasta     Label
## 256    M17   beds     Label
## 257     C2  faces     Label
## 258     C2 houses     Label
## 259     C2  pasta     Label
## 260     C2   beds     Label
## 261    C23  faces     Label
## 262    C23 houses     Label
## 263    C23  pasta     Label
## 264    C23   beds     Label
## 265    M20  faces     Label
## 266    M20 houses     Label
## 267    M20  pasta     Label
## 268    M20   beds     Label
## 269    M21  faces     Label
## 270    M21 houses     Label
## 271    M21  pasta     Label
## 272    M21   beds     Label
## 273    C21  faces     Label
## 274    C21 houses     Label
## 275    C21  pasta     Label
## 276    C21   beds     Label
## 277    M24  faces     Label
## 278    M24 houses     Label
## 279    M24  pasta     Label
## 280    M24   beds     Label
## 281     M5  faces     Label
## 282     M5 houses     Label
## 283     M5  pasta     Label
## 284     M5   beds     Label
## 285     M7  faces     Label
## 286     M7 houses     Label
## 287     M7  pasta     Label
## 288     M7   beds     Label
## 289     M8  faces     Label
## 290     M8 houses     Label
## 291     M8  pasta     Label
## 292     M8   beds     Label
## 293    C18  faces     Label
## 294    C18 houses     Label
## 295    C18  pasta     Label
## 296    C18   beds     Label
## 297    M25  faces     Label
## 298    M25 houses     Label
## 299    M25  pasta     Label
## 300    M25   beds     Label
## 301 MSCH47  faces  No Label
## 302 MSCH47 houses  No Label
## 303 MSCH47  pasta  No Label
## 304 MSCH47   beds  No Label
## 305 MSCH50  faces  No Label
## 306 MSCH50 houses  No Label
## 307 MSCH50  pasta  No Label
## 308 MSCH50   beds  No Label
## 309 MSCH51  faces  No Label
## 310 MSCH51 houses  No Label
## 311 MSCH51  pasta  No Label
## 312 MSCH51   beds  No Label
## 313 MSCH44  faces  No Label
## 314 MSCH44 houses  No Label
## 315 MSCH44  pasta  No Label
## 316 MSCH44   beds  No Label
## 317 MSCH52  faces  No Label
## 318 MSCH52 houses  No Label
## 319 MSCH52  pasta  No Label
## 320 MSCH52   beds  No Label
## 321 MSCH38  faces  No Label
## 322 MSCH38 houses  No Label
## 323 MSCH38  pasta  No Label
## 324 MSCH38   beds  No Label
## 325 MSCH43  faces  No Label
## 326 MSCH43 houses  No Label
## 327 MSCH43  pasta  No Label
## 328 MSCH43   beds  No Label
## 329 MSCH49  faces  No Label
## 330 MSCH49 houses  No Label
## 331 MSCH49  pasta  No Label
## 332 MSCH49   beds  No Label
## 333 MSCH45  faces  No Label
## 334 MSCH45 houses  No Label
## 335 MSCH45  pasta  No Label
## 336 MSCH45   beds  No Label
## 337 MSCH42  faces  No Label
## 338 MSCH42 houses  No Label
## 339 MSCH42  pasta  No Label
## 340 MSCH42   beds  No Label
## 341 MSCH53  faces  No Label
## 342 MSCH53 houses  No Label
## 343 MSCH53  pasta  No Label
## 344 MSCH53   beds  No Label
## 345  SCH35  faces  No Label
## 346  SCH35 houses  No Label
## 347  SCH35  pasta  No Label
## 348  SCH35   beds  No Label
## 349 MSCH40  faces  No Label
## 350 MSCH40 houses  No Label
## 351 MSCH40  pasta  No Label
## 352 MSCH40   beds  No Label
## 353  SCH34  faces  No Label
## 354  SCH34 houses  No Label
## 355  SCH34  pasta  No Label
## 356  SCH34   beds  No Label
## 357  SCH33  faces  No Label
## 358  SCH33 houses  No Label
## 359  SCH33  pasta  No Label
## 360  SCH33   beds  No Label
## 361 MSCH41  faces  No Label
## 362 MSCH41 houses  No Label
## 363 MSCH41  pasta  No Label
## 364 MSCH41   beds  No Label
## 365  SCH37   beds  No Label
## 366  SCH37  faces  No Label
## 367  SCH37 houses  No Label
## 368  SCH37  pasta  No Label
## 369  SCH32  faces  No Label
## 370  SCH32 houses  No Label
## 371  SCH32  pasta  No Label
## 372  SCH32   beds  No Label
## 373  SCH36   beds  No Label
## 374  SCH36  faces  No Label
## 375  SCH36 houses  No Label
## 376  SCH36  pasta  No Label
## 377  SCH11   beds  No Label
## 378  SCH12  faces  No Label
## 379  SCH12 houses  No Label
## 380  SCH12  pasta  No Label
## 381  SCH12   beds  No Label
## 382  SCH18  faces  No Label
## 383  SCH18 houses  No Label
## 384  SCH18  pasta  No Label
## 385  SCH18   beds  No Label
## 386 MSCH48  faces  No Label
## 387 MSCH48 houses  No Label
## 388 MSCH48  pasta  No Label
## 389 MSCH48   beds  No Label
## 390  SCH25  faces  No Label
## 391  SCH25 houses  No Label
## 392  SCH25  pasta  No Label
## 393  SCH25   beds  No Label
## 394  SCH31  faces  No Label
## 395  SCH31 houses  No Label
## 396  SCH31  pasta  No Label
## 397  SCH31   beds  No Label
## 398 MSCH46  faces  No Label
## 399 MSCH46 houses  No Label
## 400 MSCH46  pasta  No Label
## 401 MSCH46   beds  No Label
## 402  SCH11  faces  No Label
## 403  SCH11 houses  No Label
## 404  SCH11  pasta  No Label
## 405  SCH29  faces  No Label
## 406  SCH29 houses  No Label
## 407  SCH29  pasta  No Label
## 408  SCH29   beds  No Label
## 409 MSCH39   beds  No Label
## 410 MSCH39  pasta  No Label
## 411 MSCH39 houses  No Label
## 412 MSCH39  faces  No Label
## 413  SCH28  faces  No Label
## 414  SCH28 houses  No Label
## 415  SCH28  pasta  No Label
## 416  SCH28   beds  No Label
## 417  SCH22  faces  No Label
## 418  SCH22 houses  No Label
## 419  SCH22  pasta  No Label
## 420  SCH22   beds  No Label
## 421  SCH24  faces  No Label
## 422  SCH24 houses  No Label
## 423  SCH24  pasta  No Label
## 424  SCH24   beds  No Label
## 425  SCH27  faces  No Label
## 426  SCH27 houses  No Label
## 427  SCH27  pasta  No Label
## 428  SCH27   beds  No Label
## 429  SCH17  faces  No Label
## 430  SCH17 houses  No Label
## 431  SCH17  pasta  No Label
## 432  SCH17   beds  No Label
## 433  SCH10  faces  No Label
## 434  SCH10 houses  No Label
## 435  SCH10  pasta  No Label
## 436  SCH10   beds  No Label
## 437   SCH9  faces  No Label
## 438   SCH9 houses  No Label
## 439   SCH9  pasta  No Label
## 440   SCH9   beds  No Label
## 441  SCH20  faces  No Label
## 442  SCH20 houses  No Label
## 443  SCH20  pasta  No Label
## 444  SCH20   beds  No Label
## 445   SCH6  faces  No Label
## 446   SCH6 houses  No Label
## 447   SCH6  pasta  No Label
## 448   SCH6   beds  No Label
## 449   SCH7  faces  No Label
## 450   SCH7 houses  No Label
## 451   SCH7  pasta  No Label
## 452   SCH7   beds  No Label
## 453  SCH15  faces  No Label
## 454  SCH15 houses  No Label
## 455  SCH15  pasta  No Label
## 456  SCH15   beds  No Label
## 457  SCH30  faces  No Label
## 458  SCH30 houses  No Label
## 459  SCH30  pasta  No Label
## 460  SCH30   beds  No Label
## 461   SCH3  faces  No Label
## 462   SCH3 houses  No Label
## 463   SCH3  pasta  No Label
## 464   SCH3   beds  No Label
## 465  SCH26  faces  No Label
## 466  SCH26 houses  No Label
## 467  SCH26  pasta  No Label
## 468  SCH26   beds  No Label
## 469   SCH8  faces  No Label
## 470   SCH8 houses  No Label
## 471   SCH8  pasta  No Label
## 472   SCH8   beds  No Label
## 473  SCH16  faces  No Label
## 474  SCH16 houses  No Label
## 475  SCH16  pasta  No Label
## 476  SCH16   beds  No Label
## 477  SCH14  faces  No Label
## 478  SCH14 houses  No Label
## 479  SCH14  pasta  No Label
## 480  SCH14   beds  No Label
## 481   SCH2  faces  No Label
## 482   SCH2 houses  No Label
## 483   SCH2  pasta  No Label
## 484   SCH2   beds  No Label
## 485   SCH5  faces  No Label
## 486   SCH5 houses  No Label
## 487   SCH5  pasta  No Label
## 488   SCH5   beds  No Label
## 489  SCH13  faces  No Label
## 490  SCH13 houses  No Label
## 491  SCH13  pasta  No Label
## 492  SCH13   beds  No Label
## 493  SCH21  faces  No Label
## 494  SCH21 houses  No Label
## 495  SCH21  pasta  No Label
## 496  SCH21   beds  No Label
## 497  SCH19  faces  No Label
## 498  SCH19 houses  No Label
## 499  SCH19  pasta  No Label
## 500  SCH19   beds  No Label
## 501  SCH23  faces  No Label
## 502  SCH23 houses  No Label
## 503  SCH23  pasta  No Label
## 504  SCH23   beds  No Label
## 505   SCH1  faces  No Label
## 506   SCH1 houses  No Label
## 507   SCH1  pasta  No Label
## 508   SCH1   beds  No Label
## 509 MSCH66  faces  No Label
## 510 MSCH66 houses  No Label
## 511 MSCH66  pasta  No Label
## 512 MSCH66   beds  No Label
## 513 MSCH67  faces  No Label
## 514 MSCH67 houses  No Label
## 515 MSCH67  pasta  No Label
## 516 MSCH67   beds  No Label
## 517 MSCH68  faces  No Label
## 518 MSCH68 houses  No Label
## 519 MSCH68  pasta  No Label
## 520 MSCH68   beds  No Label
## 521 MSCH69  faces  No Label
## 522 MSCH69 houses  No Label
## 523 MSCH69  pasta  No Label
## 524 MSCH69   beds  No Label
## 525 MSCH70  faces  No Label
## 526 MSCH70 houses  No Label
## 527 MSCH70  pasta  No Label
## 528 MSCH70   beds  No Label
## 529 MSCH71  faces  No Label
## 530 MSCH71 houses  No Label
## 531 MSCH71  pasta  No Label
## 532 MSCH71   beds  No Label
## 533 MSCH72  faces  No Label
## 534 MSCH72 houses  No Label
## 535 MSCH72  pasta  No Label
## 536 MSCH72   beds  No Label
## 537 MSCH73  faces  No Label
## 538 MSCH73 houses  No Label
## 539 MSCH73  pasta  No Label
## 540 MSCH73   beds  No Label
## 541 MSCH74  faces  No Label
## 542 MSCH74 houses  No Label
## 543 MSCH74  pasta  No Label
## 544 MSCH74   beds  No Label
## 545 MSCH75  faces  No Label
## 546 MSCH75 houses  No Label
## 547 MSCH75  pasta  No Label
## 548 MSCH75   beds  No Label
## 549 MSCH76  faces  No Label
## 550 MSCH76 houses  No Label
## 551 MSCH76  pasta  No Label
## 552 MSCH76   beds  No Label
## 553 MSCH77  faces  No Label
## 554 MSCH77 houses  No Label
## 555 MSCH77  pasta  No Label
## 556 MSCH77   beds  No Label
## 557 MSCH78  faces  No Label
## 558 MSCH78 houses  No Label
## 559 MSCH78  pasta  No Label
## 560 MSCH78   beds  No Label
## 561 MSCH79  faces  No Label
## 562 MSCH79 houses  No Label
## 563 MSCH79  pasta  No Label
## 564 MSCH79   beds  No Label
## 565 MSCH80  faces  No Label
## 566 MSCH80 houses  No Label
## 567 MSCH80  pasta  No Label
## 568 MSCH80   beds  No Label
## 569 MSCH81  faces  No Label
## 570 MSCH81 houses  No Label
## 571 MSCH81  pasta  No Label
## 572 MSCH81   beds  No Label
## 573 MSCH82  faces  No Label
## 574 MSCH82 houses  No Label
## 575 MSCH82  pasta  No Label
## 576 MSCH82   beds  No Label
## 577 MSCH83  faces  No Label
## 578 MSCH83 houses  No Label
## 579 MSCH83  pasta  No Label
## 580 MSCH83   beds  No Label
## 581 MSCH84  faces  No Label
## 582 MSCH84 houses  No Label
## 583 MSCH84  pasta  No Label
## 584 MSCH84   beds  No Label
## 585 MSCH85  faces  No Label
## 586 MSCH85 houses  No Label
## 587 MSCH85  pasta  No Label
## 588 MSCH85   beds  No Label

There are others too, but these are the most common. Here is a table of all of them.

function what it does
starts_with() selects columns starting with a string
ends_with() selects columns that end with a string
contains() selects columns that contain a string
matches() selects columns that match a regular expression
num_ranges() selects columns that match a numerical range
one_of() selects columns whose names match entries in a character vector
everything() selects all columns
last_col() selects last column; can include an offset.

Each of these can be very useful in a given scenario.

Exercise 3.1.1a

Select all of the variables that contain the letter e in their name.

3.1.2 Filtering rows

filter() is the next verb we’ll cover today, and is used to extract rows based on logical tests.

Like select(), its first argument is the data, followed by conditions for filtering data. For example, let’s say we want to filter rows for cases in the “No Label” condition.

filter(ps_data, condition == "No Label")
##      subid   item correct  age condition
## 1   MSCH47  faces       1 2.01  No Label
## 2   MSCH47 houses       0 2.01  No Label
## 3   MSCH47  pasta       1 2.01  No Label
## 4   MSCH47   beds       0 2.01  No Label
## 5   MSCH50  faces       0 2.03  No Label
## 6   MSCH50 houses       0 2.03  No Label
## 7   MSCH50  pasta       0 2.03  No Label
## 8   MSCH50   beds       0 2.03  No Label
## 9   MSCH51  faces       0 2.07  No Label
## 10  MSCH51 houses       0 2.07  No Label
## 11  MSCH51  pasta       0 2.07  No Label
## 12  MSCH51   beds       0 2.07  No Label
## 13  MSCH44  faces       0 2.25  No Label
## 14  MSCH44 houses       0 2.25  No Label
## 15  MSCH44  pasta       0 2.25  No Label
## 16  MSCH44   beds       0 2.25  No Label
## 17  MSCH52  faces       0 2.50  No Label
## 18  MSCH52 houses       1 2.50  No Label
## 19  MSCH52  pasta       0 2.50  No Label
## 20  MSCH52   beds       1 2.50  No Label
## 21  MSCH38  faces       0 2.59  No Label
## 22  MSCH38 houses       0 2.59  No Label
## 23  MSCH38  pasta       1 2.59  No Label
## 24  MSCH38   beds       0 2.59  No Label
## 25  MSCH43  faces       0 2.71  No Label
## 26  MSCH43 houses       0 2.71  No Label
## 27  MSCH43  pasta       0 2.71  No Label
## 28  MSCH43   beds       0 2.71  No Label
## 29  MSCH49  faces       0 2.88  No Label
## 30  MSCH49 houses       0 2.88  No Label
## 31  MSCH49  pasta       0 2.88  No Label
## 32  MSCH49   beds       0 2.88  No Label
## 33  MSCH45  faces       0 2.90  No Label
## 34  MSCH45 houses       0 2.90  No Label
## 35  MSCH45  pasta       0 2.90  No Label
## 36  MSCH45   beds       1 2.90  No Label
## 37  MSCH42  faces       1 2.93  No Label
## 38  MSCH42 houses       0 2.93  No Label
## 39  MSCH42  pasta       0 2.93  No Label
## 40  MSCH42   beds       0 2.93  No Label
## 41  MSCH53  faces       1 2.99  No Label
## 42  MSCH53 houses       1 2.99  No Label
## 43  MSCH53  pasta       0 2.99  No Label
## 44  MSCH53   beds       0 2.99  No Label
## 45   SCH35  faces       0 3.02  No Label
## 46   SCH35 houses       0 3.02  No Label
## 47   SCH35  pasta       0 3.02  No Label
## 48   SCH35   beds       0 3.02  No Label
## 49  MSCH40  faces       0 3.02  No Label
## 50  MSCH40 houses       1 3.02  No Label
## 51  MSCH40  pasta       0 3.02  No Label
## 52  MSCH40   beds       1 3.02  No Label
## 53   SCH34  faces       0 3.06  No Label
## 54   SCH34 houses       0 3.06  No Label
## 55   SCH34  pasta       0 3.06  No Label
## 56   SCH34   beds       0 3.06  No Label
## 57   SCH33  faces       0 3.06  No Label
## 58   SCH33 houses       0 3.06  No Label
## 59   SCH33  pasta       0 3.06  No Label
## 60   SCH33   beds       0 3.06  No Label
## 61  MSCH41  faces       0 3.18  No Label
## 62  MSCH41 houses       0 3.18  No Label
## 63  MSCH41  pasta       0 3.18  No Label
## 64  MSCH41   beds       0 3.18  No Label
## 65   SCH37   beds       0 3.27  No Label
## 66   SCH37  faces       1 3.27  No Label
## 67   SCH37 houses       0 3.27  No Label
## 68   SCH37  pasta       1 3.27  No Label
## 69   SCH32  faces       1 3.27  No Label
## 70   SCH32 houses       0 3.27  No Label
## 71   SCH32  pasta       0 3.27  No Label
## 72   SCH32   beds       0 3.27  No Label
## 73   SCH36   beds       0 3.33  No Label
## 74   SCH36  faces       0 3.33  No Label
## 75   SCH36 houses       1 3.33  No Label
## 76   SCH36  pasta       1 3.33  No Label
## 77   SCH11   beds       0 3.41  No Label
## 78   SCH12  faces       0 3.41  No Label
## 79   SCH12 houses       0 3.41  No Label
## 80   SCH12  pasta       0 3.41  No Label
## 81   SCH12   beds       0 3.41  No Label
## 82   SCH18  faces       0 3.45  No Label
## 83   SCH18 houses       0 3.45  No Label
## 84   SCH18  pasta       0 3.45  No Label
## 85   SCH18   beds       0 3.45  No Label
## 86  MSCH48  faces       0 3.50  No Label
## 87  MSCH48 houses       1 3.50  No Label
## 88  MSCH48  pasta       0 3.50  No Label
## 89  MSCH48   beds       0 3.50  No Label
## 90   SCH25  faces       0 3.54  No Label
## 91   SCH25 houses       1 3.54  No Label
## 92   SCH25  pasta       1 3.54  No Label
## 93   SCH25   beds       0 3.54  No Label
## 94   SCH31  faces       0 3.71  No Label
## 95   SCH31 houses       0 3.71  No Label
## 96   SCH31  pasta       0 3.71  No Label
## 97   SCH31   beds       0 3.71  No Label
## 98  MSCH46  faces       0 3.76  No Label
## 99  MSCH46 houses       0 3.76  No Label
## 100 MSCH46  pasta       1 3.76  No Label
## 101 MSCH46   beds       0 3.76  No Label
## 102  SCH11  faces       1 3.82  No Label
## 103  SCH11 houses       1 3.82  No Label
## 104  SCH11  pasta       1 3.82  No Label
## 105  SCH29  faces       0 3.83  No Label
## 106  SCH29 houses       0 3.83  No Label
## 107  SCH29  pasta       0 3.83  No Label
## 108  SCH29   beds       0 3.83  No Label
## 109 MSCH39   beds       1 3.93  No Label
## 110 MSCH39  pasta       0 3.93  No Label
## 111 MSCH39 houses       0 3.94  No Label
## 112 MSCH39  faces       0 3.94  No Label
## 113  SCH28  faces       0 4.02  No Label
## 114  SCH28 houses       0 4.02  No Label
## 115  SCH28  pasta       0 4.02  No Label
## 116  SCH28   beds       0 4.02  No Label
## 117  SCH22  faces       0 4.02  No Label
## 118  SCH22 houses       0 4.02  No Label
## 119  SCH22  pasta       0 4.02  No Label
## 120  SCH22   beds       1 4.02  No Label
## 121  SCH24  faces       0 4.07  No Label
## 122  SCH24 houses       0 4.07  No Label
## 123  SCH24  pasta       1 4.07  No Label
## 124  SCH24   beds       0 4.07  No Label
## 125  SCH27  faces       0 4.09  No Label
## 126  SCH27 houses       0 4.09  No Label
## 127  SCH27  pasta       1 4.09  No Label
## 128  SCH27   beds       0 4.09  No Label
## 129  SCH17  faces       0 4.25  No Label
## 130  SCH17 houses       0 4.25  No Label
## 131  SCH17  pasta       1 4.25  No Label
## 132  SCH17   beds       0 4.25  No Label
## 133  SCH10  faces       0 4.32  No Label
## 134  SCH10 houses       0 4.32  No Label
## 135  SCH10  pasta       0 4.32  No Label
## 136  SCH10   beds       1 4.32  No Label
## 137   SCH9  faces       0 4.37  No Label
## 138   SCH9 houses       0 4.37  No Label
## 139   SCH9  pasta       0 4.37  No Label
## 140   SCH9   beds       0 4.37  No Label
## 141  SCH20  faces       0 4.39  No Label
## 142  SCH20 houses       0 4.39  No Label
## 143  SCH20  pasta       0 4.39  No Label
## 144  SCH20   beds       0 4.39  No Label
## 145   SCH6  faces       0 4.41  No Label
## 146   SCH6 houses       0 4.41  No Label
## 147   SCH6  pasta       0 4.41  No Label
## 148   SCH6   beds       0 4.41  No Label
## 149   SCH7  faces       1 4.41  No Label
## 150   SCH7 houses       0 4.41  No Label
## 151   SCH7  pasta       0 4.41  No Label
## 152   SCH7   beds       0 4.41  No Label
## 153  SCH15  faces       1 4.42  No Label
## 154  SCH15 houses       0 4.42  No Label
## 155  SCH15  pasta       0 4.42  No Label
## 156  SCH15   beds       0 4.42  No Label
## 157  SCH30  faces       0 4.44  No Label
## 158  SCH30 houses       0 4.44  No Label
## 159  SCH30  pasta       1 4.44  No Label
## 160  SCH30   beds       0 4.44  No Label
## 161   SCH3  faces       0 4.47  No Label
## 162   SCH3 houses       0 4.47  No Label
## 163   SCH3  pasta       0 4.47  No Label
## 164   SCH3   beds       0 4.47  No Label
## 165  SCH26  faces       0 4.47  No Label
## 166  SCH26 houses       0 4.47  No Label
## 167  SCH26  pasta       1 4.47  No Label
## 168  SCH26   beds       0 4.47  No Label
## 169   SCH8  faces       0 4.52  No Label
## 170   SCH8 houses       0 4.52  No Label
## 171   SCH8  pasta       0 4.52  No Label
## 172   SCH8   beds       0 4.52  No Label
## 173  SCH16  faces       0 4.55  No Label
## 174  SCH16 houses       0 4.55  No Label
## 175  SCH16  pasta       0 4.55  No Label
## 176  SCH16   beds       1 4.55  No Label
## 177  SCH14  faces       0 4.58  No Label
## 178  SCH14 houses       0 4.58  No Label
## 179  SCH14  pasta       0 4.58  No Label
## 180  SCH14   beds       1 4.58  No Label
## 181   SCH2  faces       0 4.61  No Label
## 182   SCH2 houses       0 4.61  No Label
## 183   SCH2  pasta       0 4.61  No Label
## 184   SCH2   beds       0 4.61  No Label
## 185   SCH5  faces       0 4.61  No Label
## 186   SCH5 houses       0 4.61  No Label
## 187   SCH5  pasta       0 4.61  No Label
## 188   SCH5   beds       0 4.61  No Label
## 189  SCH13  faces       0 4.75  No Label
## 190  SCH13 houses       0 4.75  No Label
## 191  SCH13  pasta       0 4.75  No Label
## 192  SCH13   beds       0 4.75  No Label
## 193  SCH21  faces       0 4.76  No Label
## 194  SCH21 houses       0 4.76  No Label
## 195  SCH21  pasta       0 4.76  No Label
## 196  SCH21   beds       0 4.76  No Label
## 197  SCH19  faces       0 4.79  No Label
## 198  SCH19 houses       0 4.79  No Label
## 199  SCH19  pasta       0 4.79  No Label
## 200  SCH19   beds       1 4.79  No Label
## 201  SCH23  faces       0 4.82  No Label
## 202  SCH23 houses       0 4.82  No Label
## 203  SCH23  pasta       0 4.82  No Label
## 204  SCH23   beds       0 4.82  No Label
## 205   SCH1  faces       0 4.82  No Label
## 206   SCH1 houses       0 4.82  No Label
## 207   SCH1  pasta       0 4.82  No Label
## 208   SCH1   beds       0 4.82  No Label
## 209 MSCH66  faces       0 3.50  No Label
## 210 MSCH66 houses       0 3.50  No Label
## 211 MSCH66  pasta       1 3.50  No Label
## 212 MSCH66   beds       0 3.50  No Label
## 213 MSCH67  faces       0 3.24  No Label
## 214 MSCH67 houses       1 3.24  No Label
## 215 MSCH67  pasta       0 3.24  No Label
## 216 MSCH67   beds       1 3.24  No Label
## 217 MSCH68  faces       0 3.94  No Label
## 218 MSCH68 houses       0 3.94  No Label
## 219 MSCH68  pasta       0 3.94  No Label
## 220 MSCH68   beds       0 3.94  No Label
## 221 MSCH69  faces       0 2.72  No Label
## 222 MSCH69 houses       1 2.72  No Label
## 223 MSCH69  pasta       1 2.72  No Label
## 224 MSCH69   beds       0 2.72  No Label
## 225 MSCH70  faces       0 2.31  No Label
## 226 MSCH70 houses       0 2.31  No Label
## 227 MSCH70  pasta       0 2.31  No Label
## 228 MSCH70   beds       1 2.31  No Label
## 229 MSCH71  faces       1 3.14  No Label
## 230 MSCH71 houses       1 3.14  No Label
## 231 MSCH71  pasta       1 3.14  No Label
## 232 MSCH71   beds       0 3.14  No Label
## 233 MSCH72  faces       1 3.72  No Label
## 234 MSCH72 houses       1 3.72  No Label
## 235 MSCH72  pasta       0 3.72  No Label
## 236 MSCH72   beds       0 3.72  No Label
## 237 MSCH73  faces       0 3.10  No Label
## 238 MSCH73 houses       0 3.10  No Label
## 239 MSCH73  pasta       0 3.10  No Label
## 240 MSCH73   beds       0 3.10  No Label
## 241 MSCH74  faces       1 2.34  No Label
## 242 MSCH74 houses       0 2.34  No Label
## 243 MSCH74  pasta       0 2.34  No Label
## 244 MSCH74   beds       1 2.34  No Label
## 245 MSCH75  faces       0 3.67  No Label
## 246 MSCH75 houses       0 3.67  No Label
## 247 MSCH75  pasta       0 3.67  No Label
## 248 MSCH75   beds       0 3.66  No Label
## 249 MSCH76  faces       0 2.58  No Label
## 250 MSCH76 houses       0 2.58  No Label
## 251 MSCH76  pasta       0 2.58  No Label
## 252 MSCH76   beds       0 2.58  No Label
## 253 MSCH77  faces       0 2.55  No Label
## 254 MSCH77 houses       0 2.55  No Label
## 255 MSCH77  pasta       0 2.55  No Label
## 256 MSCH77   beds       1 2.55  No Label
## 257 MSCH78  faces       0 2.43  No Label
## 258 MSCH78 houses       0 2.43  No Label
## 259 MSCH78  pasta       0 2.43  No Label
## 260 MSCH78   beds       1 2.43  No Label
## 261 MSCH79  faces       0 2.70  No Label
## 262 MSCH79 houses       1 2.70  No Label
## 263 MSCH79  pasta       0 2.70  No Label
## 264 MSCH79   beds       1 2.70  No Label
## 265 MSCH80  faces       0 2.76  No Label
## 266 MSCH80 houses       0 2.76  No Label
## 267 MSCH80  pasta       0 2.76  No Label
## 268 MSCH80   beds       0 2.76  No Label
## 269 MSCH81  faces       1 2.84  No Label
## 270 MSCH81 houses       0 2.84  No Label
## 271 MSCH81  pasta       0 2.84  No Label
## 272 MSCH81   beds       0 2.84  No Label
## 273 MSCH82  faces       1 2.46  No Label
## 274 MSCH82 houses       0 2.46  No Label
## 275 MSCH82  pasta       1 2.46  No Label
## 276 MSCH82   beds       0 2.46  No Label
## 277 MSCH83  faces       0 2.37  No Label
## 278 MSCH83 houses       0 2.37  No Label
## 279 MSCH83  pasta       1 2.37  No Label
## 280 MSCH83   beds       0 2.37  No Label
## 281 MSCH84  faces       0 2.83  No Label
## 282 MSCH84 houses       0 2.83  No Label
## 283 MSCH84  pasta       1 2.83  No Label
## 284 MSCH84   beds       0 2.83  No Label
## 285 MSCH85  faces       0 2.69  No Label
## 286 MSCH85 houses       0 2.69  No Label
## 287 MSCH85  pasta       0 2.69  No Label
## 288 MSCH85   beds       0 2.69  No Label

Or we could select observations from the “No Label” condition for kids 3 years old or younger:

filter(ps_data, condition == "No Label" & age <= 3)
##     subid   item correct  age condition
## 1  MSCH47  faces       1 2.01  No Label
## 2  MSCH47 houses       0 2.01  No Label
## 3  MSCH47  pasta       1 2.01  No Label
## 4  MSCH47   beds       0 2.01  No Label
## 5  MSCH50  faces       0 2.03  No Label
## 6  MSCH50 houses       0 2.03  No Label
## 7  MSCH50  pasta       0 2.03  No Label
## 8  MSCH50   beds       0 2.03  No Label
## 9  MSCH51  faces       0 2.07  No Label
## 10 MSCH51 houses       0 2.07  No Label
## 11 MSCH51  pasta       0 2.07  No Label
## 12 MSCH51   beds       0 2.07  No Label
## 13 MSCH44  faces       0 2.25  No Label
## 14 MSCH44 houses       0 2.25  No Label
## 15 MSCH44  pasta       0 2.25  No Label
## 16 MSCH44   beds       0 2.25  No Label
## 17 MSCH52  faces       0 2.50  No Label
## 18 MSCH52 houses       1 2.50  No Label
## 19 MSCH52  pasta       0 2.50  No Label
## 20 MSCH52   beds       1 2.50  No Label
## 21 MSCH38  faces       0 2.59  No Label
## 22 MSCH38 houses       0 2.59  No Label
## 23 MSCH38  pasta       1 2.59  No Label
## 24 MSCH38   beds       0 2.59  No Label
## 25 MSCH43  faces       0 2.71  No Label
## 26 MSCH43 houses       0 2.71  No Label
## 27 MSCH43  pasta       0 2.71  No Label
## 28 MSCH43   beds       0 2.71  No Label
## 29 MSCH49  faces       0 2.88  No Label
## 30 MSCH49 houses       0 2.88  No Label
## 31 MSCH49  pasta       0 2.88  No Label
## 32 MSCH49   beds       0 2.88  No Label
## 33 MSCH45  faces       0 2.90  No Label
## 34 MSCH45 houses       0 2.90  No Label
## 35 MSCH45  pasta       0 2.90  No Label
## 36 MSCH45   beds       1 2.90  No Label
## 37 MSCH42  faces       1 2.93  No Label
## 38 MSCH42 houses       0 2.93  No Label
## 39 MSCH42  pasta       0 2.93  No Label
## 40 MSCH42   beds       0 2.93  No Label
## 41 MSCH53  faces       1 2.99  No Label
## 42 MSCH53 houses       1 2.99  No Label
## 43 MSCH53  pasta       0 2.99  No Label
## 44 MSCH53   beds       0 2.99  No Label
## 45 MSCH69  faces       0 2.72  No Label
## 46 MSCH69 houses       1 2.72  No Label
## 47 MSCH69  pasta       1 2.72  No Label
## 48 MSCH69   beds       0 2.72  No Label
## 49 MSCH70  faces       0 2.31  No Label
## 50 MSCH70 houses       0 2.31  No Label
## 51 MSCH70  pasta       0 2.31  No Label
## 52 MSCH70   beds       1 2.31  No Label
## 53 MSCH74  faces       1 2.34  No Label
## 54 MSCH74 houses       0 2.34  No Label
## 55 MSCH74  pasta       0 2.34  No Label
## 56 MSCH74   beds       1 2.34  No Label
## 57 MSCH76  faces       0 2.58  No Label
## 58 MSCH76 houses       0 2.58  No Label
## 59 MSCH76  pasta       0 2.58  No Label
## 60 MSCH76   beds       0 2.58  No Label
## 61 MSCH77  faces       0 2.55  No Label
## 62 MSCH77 houses       0 2.55  No Label
## 63 MSCH77  pasta       0 2.55  No Label
## 64 MSCH77   beds       1 2.55  No Label
## 65 MSCH78  faces       0 2.43  No Label
## 66 MSCH78 houses       0 2.43  No Label
## 67 MSCH78  pasta       0 2.43  No Label
## 68 MSCH78   beds       1 2.43  No Label
## 69 MSCH79  faces       0 2.70  No Label
## 70 MSCH79 houses       1 2.70  No Label
## 71 MSCH79  pasta       0 2.70  No Label
## 72 MSCH79   beds       1 2.70  No Label
## 73 MSCH80  faces       0 2.76  No Label
## 74 MSCH80 houses       0 2.76  No Label
## 75 MSCH80  pasta       0 2.76  No Label
## 76 MSCH80   beds       0 2.76  No Label
## 77 MSCH81  faces       1 2.84  No Label
## 78 MSCH81 houses       0 2.84  No Label
## 79 MSCH81  pasta       0 2.84  No Label
## 80 MSCH81   beds       0 2.84  No Label
## 81 MSCH82  faces       1 2.46  No Label
## 82 MSCH82 houses       0 2.46  No Label
## 83 MSCH82  pasta       1 2.46  No Label
## 84 MSCH82   beds       0 2.46  No Label
## 85 MSCH83  faces       0 2.37  No Label
## 86 MSCH83 houses       0 2.37  No Label
## 87 MSCH83  pasta       1 2.37  No Label
## 88 MSCH83   beds       0 2.37  No Label
## 89 MSCH84  faces       0 2.83  No Label
## 90 MSCH84 houses       0 2.83  No Label
## 91 MSCH84  pasta       1 2.83  No Label
## 92 MSCH84   beds       0 2.83  No Label
## 93 MSCH85  faces       0 2.69  No Label
## 94 MSCH85 houses       0 2.69  No Label
## 95 MSCH85  pasta       0 2.69  No Label
## 96 MSCH85   beds       0 2.69  No Label

We can also filter for observations that meet one condition or another, using | for OR. Let’s get observations for kids younger than 3 or in the no label condition

filter(ps_data, condition == "Label" | age <= 3)
##      subid   item correct  age condition
## 1      M22  faces       1 2.00     Label
## 2      M22 houses       1 2.00     Label
## 3      M22  pasta       0 2.00     Label
## 4      M22   beds       0 2.00     Label
## 5      T22   beds       0 2.13     Label
## 6      T22  faces       0 2.13     Label
## 7      T22 houses       1 2.13     Label
## 8      T22  pasta       1 2.13     Label
## 9      T17  pasta       0 2.32     Label
## 10     T17  faces       0 2.32     Label
## 11     T17 houses       0 2.32     Label
## 12     T17   beds       0 2.32     Label
## 13      M3  faces       0 2.38     Label
## 14      M3 houses       1 2.38     Label
## 15      M3  pasta       1 2.38     Label
## 16      M3   beds       1 2.38     Label
## 17     T19  faces       0 2.47     Label
## 18     T19 houses       0 2.47     Label
## 19     T19  pasta       1 2.47     Label
## 20     T19   beds       1 2.47     Label
## 21     T20  faces       1 2.50     Label
## 22     T20 houses       1 2.50     Label
## 23     T20  pasta       0 2.50     Label
## 24     T20   beds       1 2.50     Label
## 25     T21  faces       1 2.58     Label
## 26     T21 houses       1 2.58     Label
## 27     T21  pasta       1 2.58     Label
## 28     T21   beds       0 2.58     Label
## 29     M26  faces       1 2.59     Label
## 30     M26 houses       1 2.59     Label
## 31     M26  pasta       0 2.59     Label
## 32     M26   beds       1 2.59     Label
## 33     T18  faces       1 2.61     Label
## 34     T18 houses       0 2.61     Label
## 35     T18  pasta       1 2.61     Label
## 36     T18   beds       0 2.61     Label
## 37     T12   beds       0 2.72     Label
## 38     T12  faces       0 2.72     Label
## 39     T12 houses       1 2.72     Label
## 40     T12  pasta       0 2.72     Label
## 41     T16  faces       1 2.73     Label
## 42     T16 houses       0 2.73     Label
## 43     T16  pasta       1 2.73     Label
## 44     T16   beds       1 2.73     Label
## 45      T7  faces       1 2.74     Label
## 46      T7 houses       0 2.74     Label
## 47      T7  pasta       0 2.74     Label
## 48      T7   beds       0 2.74     Label
## 49      T9 houses       0 2.79     Label
## 50      T9  faces       1 2.79     Label
## 51      T9  pasta       0 2.79     Label
## 52      T9   beds       1 2.79     Label
## 53      T5  faces       1 2.80     Label
## 54      T5 houses       1 2.80     Label
## 55      T5  pasta       0 2.80     Label
## 56      T5   beds       1 2.80     Label
## 57     T14  faces       1 2.83     Label
## 58     T14 houses       1 2.83     Label
## 59     T14  pasta       0 2.83     Label
## 60     T14   beds       1 2.83     Label
## 61      T2 houses       0 2.83     Label
## 62      T2  faces       0 2.83     Label
## 63      T2  pasta       1 2.83     Label
## 64      T2   beds       1 2.83     Label
## 65     T15  faces       0 2.85     Label
## 66     T15 houses       0 2.85     Label
## 67     T15  pasta       1 2.85     Label
## 68     T15   beds       0 2.85     Label
## 69     M13 houses       0 2.88     Label
## 70     M13   beds       1 2.88     Label
## 71     M13  faces       1 2.88     Label
## 72     M13  pasta       0 2.88     Label
## 73     M12  faces       1 2.88     Label
## 74     M12 houses       0 2.88     Label
## 75     M12  pasta       1 2.88     Label
## 76     M12   beds       0 2.88     Label
## 77     T13   beds       0 2.89     Label
## 78     T13  faces       0 2.89     Label
## 79     T13 houses       1 2.89     Label
## 80     T13  pasta       1 2.89     Label
## 81      T8  faces       1 2.91     Label
## 82      T8 houses       0 2.91     Label
## 83      T8  pasta       1 2.91     Label
## 84      T8   beds       1 2.91     Label
## 85      T1  faces       1 2.95     Label
## 86      T1 houses       0 2.95     Label
## 87      T1  pasta       0 2.95     Label
## 88      T1   beds       1 2.95     Label
## 89     M15  faces       1 2.98     Label
## 90     M15 houses       1 2.98     Label
## 91     M15  pasta       1 2.98     Label
## 92     M15   beds       1 2.98     Label
## 93     T11  faces       1 2.99     Label
## 94     T11 houses       0 2.99     Label
## 95     T11  pasta       1 2.99     Label
## 96     T11   beds       1 2.99     Label
## 97     T10  faces       0 3.00     Label
## 98     T10 houses       1 3.00     Label
## 99     T10  pasta       1 3.00     Label
## 100    T10   beds       1 3.00     Label
## 101     T3  faces       1 3.09     Label
## 102     T3 houses       1 3.09     Label
## 103     T3  pasta       1 3.09     Label
## 104     T3   beds       1 3.09     Label
## 105     T6  faces       1 3.10     Label
## 106     T6 houses       1 3.10     Label
## 107     T6  pasta       1 3.10     Label
## 108     T6   beds       1 3.10     Label
## 109    M32   beds       1 3.19     Label
## 110    M32  faces       1 3.19     Label
## 111    M32 houses       0 3.19     Label
## 112    M32  pasta       1 3.19     Label
## 113     M1  faces       0 3.20     Label
## 114     M1   beds       1 3.20     Label
## 115     M1  pasta       0 3.20     Label
## 116     M1 houses       0 3.20     Label
## 117    C16  faces       0 3.22     Label
## 118    C16 houses       0 3.22     Label
## 119    C16  pasta       1 3.22     Label
## 120    C16   beds       1 3.22     Label
## 121     T4  faces       1 3.24     Label
## 122     T4 houses       0 3.24     Label
## 123     T4  pasta       0 3.24     Label
## 124     T4   beds       1 3.24     Label
## 125    C17  faces       1 3.25     Label
## 126    C17 houses       0 3.25     Label
## 127    C17  pasta       1 3.25     Label
## 128    C17   beds       0 3.25     Label
## 129     C6  faces       0 3.26     Label
## 130     C6 houses       1 3.26     Label
## 131     C6  pasta       1 3.26     Label
## 132     C6   beds       1 3.26     Label
## 133    M10  faces       1 3.28     Label
## 134    M10 houses       1 3.28     Label
## 135    M10   beds       1 3.28     Label
## 136    M10  pasta       1 3.28     Label
## 137    M31  faces       0 3.30     Label
## 138    M31 houses       1 3.30     Label
## 139    M31  pasta       1 3.30     Label
## 140    M31   beds       1 3.30     Label
## 141     C3 houses       0 3.46     Label
## 142     C3  pasta       1 3.46     Label
## 143     C3   beds       1 3.46     Label
## 144     C3  faces       1 3.46     Label
## 145    C10  faces       0 3.46     Label
## 146    C10 houses       0 3.46     Label
## 147    C10  pasta       1 3.46     Label
## 148    C10   beds       1 3.46     Label
## 149    M18  faces       0 3.46     Label
## 150    M18 houses       1 3.46     Label
## 151    M18  pasta       1 3.46     Label
## 152    M18   beds       1 3.46     Label
## 153    M16  faces       0 3.50     Label
## 154    M16 houses       0 3.50     Label
## 155    M16  pasta       0 3.50     Label
## 156    M16   beds       1 3.50     Label
## 157    M23  faces       1 3.52     Label
## 158    M23 houses       0 3.52     Label
## 159    M23  pasta       1 3.52     Label
## 160    M23   beds       1 3.52     Label
## 161     C7  faces       0 3.55     Label
## 162     C7 houses       1 3.55     Label
## 163     C7  pasta       0 3.55     Label
## 164     C7   beds       0 3.55     Label
## 165    C12  faces       1 3.56     Label
## 166    C12 houses       0 3.56     Label
## 167    C12  pasta       1 3.56     Label
## 168    C12   beds       1 3.56     Label
## 169    C15  faces       1 3.59     Label
## 170    C15 houses       1 3.59     Label
## 171    C15  pasta       1 3.59     Label
## 172    C15   beds       1 3.59     Label
## 173    M29  faces       0 3.72     Label
## 174    M29 houses       1 3.72     Label
## 175    M29  pasta       1 3.72     Label
## 176    M29   beds       1 3.72     Label
## 177    C20  faces       1 3.75     Label
## 178    C20 houses       1 3.75     Label
## 179    C20  pasta       1 3.75     Label
## 180    C20   beds       1 3.75     Label
## 181    M11  faces       1 3.82     Label
## 182    M11 houses       0 3.82     Label
## 183    M11  pasta       1 3.82     Label
## 184    M11   beds       1 3.82     Label
## 185     C9   beds       1 3.82     Label
## 186     C9  faces       1 3.82     Label
## 187     C9 houses       1 3.82     Label
## 188     C9  pasta       1 3.82     Label
## 189    C24  faces       1 3.85     Label
## 190    C24 houses       0 3.85     Label
## 191    C24  pasta       0 3.85     Label
## 192    C24   beds       1 3.85     Label
## 193    C22  faces       0 3.92     Label
## 194    C22 houses       0 3.92     Label
## 195    C22  pasta       1 3.92     Label
## 196    C22   beds       1 3.92     Label
## 197     C8  faces       1 3.92     Label
## 198     C8 houses       1 3.92     Label
## 199     C8  pasta       1 3.92     Label
## 200     C8   beds       1 3.92     Label
## 201     M4  faces       1 3.96     Label
## 202     M4 houses       1 3.96     Label
## 203     M4  pasta       1 3.96     Label
## 204     M4   beds       1 3.96     Label
## 205     M6  faces       0 4.50     Label
## 206     M6 houses       1 4.50     Label
## 207     M6  pasta       1 4.50     Label
## 208     M6   beds       0 4.50     Label
## 209    C19  faces       1 4.14     Label
## 210    C19 houses       0 4.14     Label
## 211    C19  pasta       0 4.14     Label
## 212    C19   beds       1 4.14     Label
## 213     C1  faces       1 4.16     Label
## 214     C1 houses       1 4.16     Label
## 215     C1  pasta       1 4.16     Label
## 216     C1   beds       1 4.16     Label
## 217    M19   beds       1 4.16     Label
## 218    M19  faces       0 4.16     Label
## 219    M19 houses       0 4.16     Label
## 220    M19  pasta       1 4.16     Label
## 221    C11  faces       1 4.22     Label
## 222    C11 houses       0 4.22     Label
## 223    C11  pasta       1 4.22     Label
## 224    C11   beds       1 4.22     Label
## 225     M9  faces       1 4.26     Label
## 226     M9 houses       1 4.26     Label
## 227     M9  pasta       1 4.26     Label
## 228     M9   beds       1 4.26     Label
## 229     M2  faces       1 4.28     Label
## 230     M2 houses       0 4.28     Label
## 231     M2  pasta       1 4.28     Label
## 232     M2   beds       1 4.28     Label
## 233     C5  faces       1 4.29     Label
## 234     C5 houses       1 4.29     Label
## 235     C5  pasta       1 4.29     Label
## 236     C5   beds       1 4.29     Label
## 237    M30   beds       1 4.33     Label
## 238    M30  faces       1 4.33     Label
## 239    M30 houses       0 4.33     Label
## 240    M30  pasta       1 4.33     Label
## 241    C13  faces       0 4.38     Label
## 242    C13 houses       1 4.38     Label
## 243    C13  pasta       0 4.38     Label
## 244    C13   beds       1 4.38     Label
## 245     C4  faces       1 4.55     Label
## 246     C4 houses       1 4.55     Label
## 247     C4  pasta       1 4.55     Label
## 248     C4   beds       1 4.55     Label
## 249    C14  faces       1 4.57     Label
## 250    C14 houses       1 4.57     Label
## 251    C14  pasta       0 4.57     Label
## 252    C14   beds       1 4.57     Label
## 253    M17  faces       1 4.58     Label
## 254    M17 houses       1 4.58     Label
## 255    M17  pasta       1 4.58     Label
## 256    M17   beds       1 4.58     Label
## 257     C2  faces       1 4.60     Label
## 258     C2 houses       1 4.60     Label
## 259     C2  pasta       1 4.60     Label
## 260     C2   beds       1 4.60     Label
## 261    C23  faces       0 4.62     Label
## 262    C23 houses       1 4.62     Label
## 263    C23  pasta       1 4.62     Label
## 264    C23   beds       0 4.62     Label
## 265    M20  faces       0 4.64     Label
## 266    M20 houses       0 4.64     Label
## 267    M20  pasta       1 4.64     Label
## 268    M20   beds       1 4.64     Label
## 269    M21  faces       1 4.64     Label
## 270    M21 houses       1 4.64     Label
## 271    M21  pasta       1 4.64     Label
## 272    M21   beds       1 4.64     Label
## 273    C21  faces       1 4.73     Label
## 274    C21 houses       0 4.73     Label
## 275    C21  pasta       1 4.73     Label
## 276    C21   beds       1 4.73     Label
## 277    M24  faces       1 4.82     Label
## 278    M24 houses       1 4.82     Label
## 279    M24  pasta       1 4.82     Label
## 280    M24   beds       1 4.82     Label
## 281     M5  faces       0 4.84     Label
## 282     M5 houses       0 4.84     Label
## 283     M5  pasta       0 4.84     Label
## 284     M5   beds       1 4.84     Label
## 285     M7  faces       1 4.89     Label
## 286     M7 houses       1 4.89     Label
## 287     M7  pasta       1 4.89     Label
## 288     M7   beds       0 4.89     Label
## 289     M8  faces       1 4.89     Label
## 290     M8 houses       1 4.89     Label
## 291     M8  pasta       1 4.89     Label
## 292     M8   beds       1 4.89     Label
## 293    C18  faces       0 4.95     Label
## 294    C18 houses       1 4.95     Label
## 295    C18  pasta       1 4.95     Label
## 296    C18   beds       1 4.95     Label
## 297    M25  faces       1 4.96     Label
## 298    M25 houses       1 4.96     Label
## 299    M25  pasta       1 4.96     Label
## 300    M25   beds       1 4.96     Label
## 301 MSCH47  faces       1 2.01  No Label
## 302 MSCH47 houses       0 2.01  No Label
## 303 MSCH47  pasta       1 2.01  No Label
## 304 MSCH47   beds       0 2.01  No Label
## 305 MSCH50  faces       0 2.03  No Label
## 306 MSCH50 houses       0 2.03  No Label
## 307 MSCH50  pasta       0 2.03  No Label
## 308 MSCH50   beds       0 2.03  No Label
## 309 MSCH51  faces       0 2.07  No Label
## 310 MSCH51 houses       0 2.07  No Label
## 311 MSCH51  pasta       0 2.07  No Label
## 312 MSCH51   beds       0 2.07  No Label
## 313 MSCH44  faces       0 2.25  No Label
## 314 MSCH44 houses       0 2.25  No Label
## 315 MSCH44  pasta       0 2.25  No Label
## 316 MSCH44   beds       0 2.25  No Label
## 317 MSCH52  faces       0 2.50  No Label
## 318 MSCH52 houses       1 2.50  No Label
## 319 MSCH52  pasta       0 2.50  No Label
## 320 MSCH52   beds       1 2.50  No Label
## 321 MSCH38  faces       0 2.59  No Label
## 322 MSCH38 houses       0 2.59  No Label
## 323 MSCH38  pasta       1 2.59  No Label
## 324 MSCH38   beds       0 2.59  No Label
## 325 MSCH43  faces       0 2.71  No Label
## 326 MSCH43 houses       0 2.71  No Label
## 327 MSCH43  pasta       0 2.71  No Label
## 328 MSCH43   beds       0 2.71  No Label
## 329 MSCH49  faces       0 2.88  No Label
## 330 MSCH49 houses       0 2.88  No Label
## 331 MSCH49  pasta       0 2.88  No Label
## 332 MSCH49   beds       0 2.88  No Label
## 333 MSCH45  faces       0 2.90  No Label
## 334 MSCH45 houses       0 2.90  No Label
## 335 MSCH45  pasta       0 2.90  No Label
## 336 MSCH45   beds       1 2.90  No Label
## 337 MSCH42  faces       1 2.93  No Label
## 338 MSCH42 houses       0 2.93  No Label
## 339 MSCH42  pasta       0 2.93  No Label
## 340 MSCH42   beds       0 2.93  No Label
## 341 MSCH53  faces       1 2.99  No Label
## 342 MSCH53 houses       1 2.99  No Label
## 343 MSCH53  pasta       0 2.99  No Label
## 344 MSCH53   beds       0 2.99  No Label
## 345 MSCH69  faces       0 2.72  No Label
## 346 MSCH69 houses       1 2.72  No Label
## 347 MSCH69  pasta       1 2.72  No Label
## 348 MSCH69   beds       0 2.72  No Label
## 349 MSCH70  faces       0 2.31  No Label
## 350 MSCH70 houses       0 2.31  No Label
## 351 MSCH70  pasta       0 2.31  No Label
## 352 MSCH70   beds       1 2.31  No Label
## 353 MSCH74  faces       1 2.34  No Label
## 354 MSCH74 houses       0 2.34  No Label
## 355 MSCH74  pasta       0 2.34  No Label
## 356 MSCH74   beds       1 2.34  No Label
## 357 MSCH76  faces       0 2.58  No Label
## 358 MSCH76 houses       0 2.58  No Label
## 359 MSCH76  pasta       0 2.58  No Label
## 360 MSCH76   beds       0 2.58  No Label
## 361 MSCH77  faces       0 2.55  No Label
## 362 MSCH77 houses       0 2.55  No Label
## 363 MSCH77  pasta       0 2.55  No Label
## 364 MSCH77   beds       1 2.55  No Label
## 365 MSCH78  faces       0 2.43  No Label
## 366 MSCH78 houses       0 2.43  No Label
## 367 MSCH78  pasta       0 2.43  No Label
## 368 MSCH78   beds       1 2.43  No Label
## 369 MSCH79  faces       0 2.70  No Label
## 370 MSCH79 houses       1 2.70  No Label
## 371 MSCH79  pasta       0 2.70  No Label
## 372 MSCH79   beds       1 2.70  No Label
## 373 MSCH80  faces       0 2.76  No Label
## 374 MSCH80 houses       0 2.76  No Label
## 375 MSCH80  pasta       0 2.76  No Label
## 376 MSCH80   beds       0 2.76  No Label
## 377 MSCH81  faces       1 2.84  No Label
## 378 MSCH81 houses       0 2.84  No Label
## 379 MSCH81  pasta       0 2.84  No Label
## 380 MSCH81   beds       0 2.84  No Label
## 381 MSCH82  faces       1 2.46  No Label
## 382 MSCH82 houses       0 2.46  No Label
## 383 MSCH82  pasta       1 2.46  No Label
## 384 MSCH82   beds       0 2.46  No Label
## 385 MSCH83  faces       0 2.37  No Label
## 386 MSCH83 houses       0 2.37  No Label
## 387 MSCH83  pasta       1 2.37  No Label
## 388 MSCH83   beds       0 2.37  No Label
## 389 MSCH84  faces       0 2.83  No Label
## 390 MSCH84 houses       0 2.83  No Label
## 391 MSCH84  pasta       1 2.83  No Label
## 392 MSCH84   beds       0 2.83  No Label
## 393 MSCH85  faces       0 2.69  No Label
## 394 MSCH85 houses       0 2.69  No Label
## 395 MSCH85  pasta       0 2.69  No Label
## 396 MSCH85   beds       0 2.69  No Label

dplyr also has a few helper functions for more advanced filtering. One that is pretty useful is between(). Let’s use it to get kids between ages 2.1 and 2.5:

filter(ps_data, between(age, 2.1, 2.5))
##     subid   item correct  age condition
## 1     T22   beds       0 2.13     Label
## 2     T22  faces       0 2.13     Label
## 3     T22 houses       1 2.13     Label
## 4     T22  pasta       1 2.13     Label
## 5     T17  pasta       0 2.32     Label
## 6     T17  faces       0 2.32     Label
## 7     T17 houses       0 2.32     Label
## 8     T17   beds       0 2.32     Label
## 9      M3  faces       0 2.38     Label
## 10     M3 houses       1 2.38     Label
## 11     M3  pasta       1 2.38     Label
## 12     M3   beds       1 2.38     Label
## 13    T19  faces       0 2.47     Label
## 14    T19 houses       0 2.47     Label
## 15    T19  pasta       1 2.47     Label
## 16    T19   beds       1 2.47     Label
## 17    T20  faces       1 2.50     Label
## 18    T20 houses       1 2.50     Label
## 19    T20  pasta       0 2.50     Label
## 20    T20   beds       1 2.50     Label
## 21 MSCH44  faces       0 2.25  No Label
## 22 MSCH44 houses       0 2.25  No Label
## 23 MSCH44  pasta       0 2.25  No Label
## 24 MSCH44   beds       0 2.25  No Label
## 25 MSCH52  faces       0 2.50  No Label
## 26 MSCH52 houses       1 2.50  No Label
## 27 MSCH52  pasta       0 2.50  No Label
## 28 MSCH52   beds       1 2.50  No Label
## 29 MSCH70  faces       0 2.31  No Label
## 30 MSCH70 houses       0 2.31  No Label
## 31 MSCH70  pasta       0 2.31  No Label
## 32 MSCH70   beds       1 2.31  No Label
## 33 MSCH74  faces       1 2.34  No Label
## 34 MSCH74 houses       0 2.34  No Label
## 35 MSCH74  pasta       0 2.34  No Label
## 36 MSCH74   beds       1 2.34  No Label
## 37 MSCH78  faces       0 2.43  No Label
## 38 MSCH78 houses       0 2.43  No Label
## 39 MSCH78  pasta       0 2.43  No Label
## 40 MSCH78   beds       1 2.43  No Label
## 41 MSCH82  faces       1 2.46  No Label
## 42 MSCH82 houses       0 2.46  No Label
## 43 MSCH82  pasta       1 2.46  No Label
## 44 MSCH82   beds       0 2.46  No Label
## 45 MSCH83  faces       0 2.37  No Label
## 46 MSCH83 houses       0 2.37  No Label
## 47 MSCH83  pasta       1 2.37  No Label
## 48 MSCH83   beds       0 2.37  No Label

Exercise 3.2a

Get Kids between the ages of 3 and 4 using filter() and the between() helper function.

Exercise 3.2b

Get Kids between ages of 3 and 4 using filter() without using the between() function.

3.3. Pipes

Pipes come from the magrittr library are available when you load the tidyverse (probably unnecessary sidenote: they’re technically imported with dplyr when you call library(tidyverse)). Pipes are a way to write strings of functions more easily, creating pipelines. They are extremely powerful and useful. A pipe looks like this:

%>%

You can enter a pipe with the shortcut CTRL+Shift+M for PC; CMD+Shift+M for Mac.

3.3.1 A quick side note about the term pipe

As mentioned above, a pipe in piping syntax is symbolized by %>%. However, another character is sometimes called a pipe, which is the vertical bar |, which we saw with logical tests above (| means or in logical statements).

3.3.2 The logic of piping syntax

The general idea of piping syntax, is that we have some function on the left hand and right hand side of the pipe. The function on the left side is evaluated, and then the output of that function is passed to the function on the right hand side of the pipe as the first argument of that (RHS) function. Let’s start with a simple example. We’ll get the sum of the age variable from the ps_data.

You can think of pipes as standing in for then.

ps_data$age %>% # LHS is age vector from ps_data
  sum() # pass that to the sum function
## [1] 2072.44

As you can see, on the left hand side of the pipe %>%, we have the age vector from ps_data. On the right hand side, we have the function sum(), so the piped syntax is basically saying Take age from PS_data then get the sum.

We can make this look even a little cleaner by using the select() function:

ps_data %>% # take the data, then...
  select(age) %>%  # select age, then...
  sum() # take the sum
## [1] 2072.44

Notice that we entered age as an argument in select and it looks like the first argument. Looks can be deceiving; the first argument is actually .data = ps_data, but that is hidden from view when piping.

Style Tip: It’s typically considered good practice to not have more than one pipe per line.

Bad:

ps_data %>% select(age) %>% sum() 
## [1] 2072.44

Good:

ps_data %>%
  select(age) %>% 
  sum() 
## [1] 2072.44

3.3.3 Why use pipes?

The most important and most often mentioned reasons to use pipes are cleanliness (which I hear is next to godliness) and efficiency:

  1. Cleaner code
    • This is nice, because it helps make your code more readable by other humans (including your future self).

Piped:

ps_data %>% # take the data, then...
  select(age) %>%  # select age, then...
  sum()
## [1] 2072.44

VS Nested:

sum(select(ps_data, age), na.rm = TRUE)
## [1] 2072.44
  1. Cleaner environment
    • When you use pipes, you have basically no reason to save objects from intermediary steps in your data wrangling / analysis workflow, because you can just pass output from function to function without saving it.
    • Finding object you’re looking for is easier.
    • Auto complete (with tab) a little more efficient.
  2. Efficiency
    • This is efficiency for you, the person doing the coding (not more efficient computing).
    • Naming objects is hard; piping means coming up with fewer names.
  3. More error-proof
    • Because naming is hard, you might accidentally re-use a name and make an error.

3.3.4 A note about Scaling

The gains in cleanliness and efficiency scale with the complexity of what you’re doing.

Let’s say, we wanted to take our PS_data, filter for observations from kids between 2.5 and 3.2, and then select just the subject id and age variables, and then get unique kids (using the unique() function on the subject id).

Without pipes, you’ll either end up with some difficult to read code:

unique(select(filter(ps_data, age > 2.5 | age < 3.2), age, subid))

or some throwaway objects:

data_subset_age <- filter(ps_data, age > 2.5 | age > 3.2)

data_subset_age_ids <- select(data_subset_age, subid, age)

unique(data_subset_age_ids)

With pipes, we can avoid these issues:

ps_data %>% # take the data, then...
  filter(age > 2.5 | age > 3.2) %>% # filter for kids between 2.5 and 3.2, then...
  select(subid, age) %>% # select subject id and centered age, then...
  unique() # get unique rows
##      subid  age
## 1      T21 2.58
## 5      M26 2.59
## 9      T18 2.61
## 13     T12 2.72
## 17     T16 2.73
## 21      T7 2.74
## 25      T9 2.79
## 29      T5 2.80
## 33     T14 2.83
## 37      T2 2.83
## 41     T15 2.85
## 45     M13 2.88
## 49     M12 2.88
## 53     T13 2.89
## 57      T8 2.91
## 61      T1 2.95
## 65     M15 2.98
## 69     T11 2.99
## 73     T10 3.00
## 77      T3 3.09
## 81      T6 3.10
## 85     M32 3.19
## 89      M1 3.20
## 93     C16 3.22
## 97      T4 3.24
## 101    C17 3.25
## 105     C6 3.26
## 109    M10 3.28
## 113    M31 3.30
## 117     C3 3.46
## 121    C10 3.46
## 125    M18 3.46
## 129    M16 3.50
## 133    M23 3.52
## 137     C7 3.55
## 141    C12 3.56
## 145    C15 3.59
## 149    M29 3.72
## 153    C20 3.75
## 157    M11 3.82
## 161     C9 3.82
## 165    C24 3.85
## 169    C22 3.92
## 173     C8 3.92
## 177     M4 3.96
## 181     M6 4.50
## 185    C19 4.14
## 189     C1 4.16
## 193    M19 4.16
## 197    C11 4.22
## 201     M9 4.26
## 205     M2 4.28
## 209     C5 4.29
## 213    M30 4.33
## 217    C13 4.38
## 221     C4 4.55
## 225    C14 4.57
## 229    M17 4.58
## 233     C2 4.60
## 237    C23 4.62
## 241    M20 4.64
## 245    M21 4.64
## 249    C21 4.73
## 253    M24 4.82
## 257     M5 4.84
## 261     M7 4.89
## 265     M8 4.89
## 269    C18 4.95
## 273    M25 4.96
## 277 MSCH38 2.59
## 281 MSCH43 2.71
## 285 MSCH49 2.88
## 289 MSCH45 2.90
## 293 MSCH42 2.93
## 297 MSCH53 2.99
## 301  SCH35 3.02
## 305 MSCH40 3.02
## 309  SCH34 3.06
## 313  SCH33 3.06
## 317 MSCH41 3.18
## 321  SCH37 3.27
## 325  SCH32 3.27
## 329  SCH36 3.33
## 333  SCH11 3.41
## 334  SCH12 3.41
## 338  SCH18 3.45
## 342 MSCH48 3.50
## 346  SCH25 3.54
## 350  SCH31 3.71
## 354 MSCH46 3.76
## 358  SCH11 3.82
## 361  SCH29 3.83
## 365 MSCH39 3.93
## 367 MSCH39 3.94
## 369  SCH28 4.02
## 373  SCH22 4.02
## 377  SCH24 4.07
## 381  SCH27 4.09
## 385  SCH17 4.25
## 389  SCH10 4.32
## 393   SCH9 4.37
## 397  SCH20 4.39
## 401   SCH6 4.41
## 405   SCH7 4.41
## 409  SCH15 4.42
## 413  SCH30 4.44
## 417   SCH3 4.47
## 421  SCH26 4.47
## 425   SCH8 4.52
## 429  SCH16 4.55
## 433  SCH14 4.58
## 437   SCH2 4.61
## 441   SCH5 4.61
## 445  SCH13 4.75
## 449  SCH21 4.76
## 453  SCH19 4.79
## 457  SCH23 4.82
## 461   SCH1 4.82
## 465 MSCH66 3.50
## 469 MSCH67 3.24
## 473 MSCH68 3.94
## 477 MSCH69 2.72
## 481 MSCH71 3.14
## 485 MSCH72 3.72
## 489 MSCH73 3.10
## 493 MSCH75 3.67
## 496 MSCH75 3.66
## 497 MSCH76 2.58
## 501 MSCH77 2.55
## 505 MSCH79 2.70
## 509 MSCH80 2.76
## 513 MSCH81 2.84
## 517 MSCH84 2.83
## 521 MSCH85 2.69

See, so much easier to read, and not flooding our environment with clutter and not taxing our already taxed minds with having to come up with a bunch of names. And keep in mind this is just chaining a few of commands together; it really pays off as you do more and more complicated things.

3.3.5 Saving the output of your pipe

Keep in mind that, like everything in R, you have to tell R to save the output of your pipe using the <-.

unique_filtered_data <- ps_data %>% # take the data, then...
  filter(age > 2.5 | age > 3.2) %>% # filter for kids between 2.5 and 3.2, then...
  select(subid, age) %>% # select subject id and centered age, then...
  unique() # get unique rows

Exercise 3.3a

Take the ps_data data set. Using select and filter, get the number correct for kids at least 4 years old (note: there are several ways to do this, but the sum() function may be helpful). The output of your pipe should be a single number.

4. Diving deeper into dplyr

We gained a little bit of familiarity with dplyr above as an intro to the tidyverse. Now, we’ll dive a little deeper and explore some of the other ways we can transform data using the grammar of data manipulation.

4.1 More on select()

Let’s review what we learned using about selecting columns. We’ll use the starwars dataset, which comes with dplyr.

4.1.1 basic selects

Recall that one easy way to select columns is to use select(), providing the data as the first argument (w/ or w/o pipes) and desired unquoted column names separated by a comma:

starwars %>% 
  select(name, homeworld)
## # A tibble: 87 x 2
##    name               homeworld
##    <chr>              <chr>    
##  1 Luke Skywalker     Tatooine 
##  2 C-3PO              Tatooine 
##  3 R2-D2              Naboo    
##  4 Darth Vader        Tatooine 
##  5 Leia Organa        Alderaan 
##  6 Owen Lars          Tatooine 
##  7 Beru Whitesun lars Tatooine 
##  8 R5-D4              Tatooine 
##  9 Biggs Darklighter  Tatooine 
## 10 Obi-Wan Kenobi     Stewjon  
## # ... with 77 more rows

4.1.2 selecting a range

Recall that we can also select a range of variables, by name. Let’s get everything from name to homeworld:

starwars %>% 
  select(name:homeworld)
## # A tibble: 87 x 9
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 1 more variable: homeworld <chr>

4.1.3 selecting with helper functions

The helper fucntions allow us to do even more advanced column selection. For example, we can get all of the columns that contain the string "color":

starwars %>% 
  select(contains("color"))
## # A tibble: 87 x 3
##    hair_color    skin_color  eye_color
##    <chr>         <chr>       <chr>    
##  1 blond         fair        blue     
##  2 <NA>          gold        yellow   
##  3 <NA>          white, blue red      
##  4 none          white       yellow   
##  5 brown         light       brown    
##  6 brown, grey   light       blue     
##  7 brown         light       blue     
##  8 <NA>          white, red  red      
##  9 black         light       brown    
## 10 auburn, white fair        blue-gray
## # ... with 77 more rows

4.1.4 Re-arranging columns with select

I didn’t mention this before, but we can also use select to re-arrange our columns. This is one of the main uses for the everything() helper function. Let’s re-arrange things so that homeworld comes first, followed by name, then by the remainin columns

starwars %>% 
  select(homeworld, name, everything())
## # A tibble: 87 x 13
##    homeworld name  height  mass hair_color skin_color eye_color birth_year
##    <chr>     <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl>
##  1 Tatooine  Luke~    172    77 blond      fair       blue            19  
##  2 Tatooine  C-3PO    167    75 <NA>       gold       yellow         112  
##  3 Naboo     R2-D2     96    32 <NA>       white, bl~ red             33  
##  4 Tatooine  Dart~    202   136 none       white      yellow          41.9
##  5 Alderaan  Leia~    150    49 brown      light      brown           19  
##  6 Tatooine  Owen~    178   120 brown, gr~ light      blue            52  
##  7 Tatooine  Beru~    165    75 brown      light      blue            47  
##  8 Tatooine  R5-D4     97    32 <NA>       white, red red             NA  
##  9 Tatooine  Bigg~    183    84 black      light      brown           24  
## 10 Stewjon   Obi-~    182    77 auburn, w~ fair       blue-gray       57  
## # ... with 77 more rows, and 5 more variables: gender <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

Exercise 4.1a

Re-arrange the starwars columns such that all of the columns that start with h are at the beginning, followed by the remaining columns.

Exercise 4.2a

Select name, species, hair_color, skin_color, and eye_color from the starwars data. Use at least one helper function.

4.2 More on filter()

Recall that filter() is sort of like the complement to select, and is for filtering the data for certain observations (rows).

4.2.1 Filters with one condition

Filters can be relatively simple. For example, we could filter for starwars characters that are less than 100cm in height:

starwars %>% 
  filter(height < 100)
## # A tibble: 7 x 13
##   name  height  mass hair_color skin_color eye_color birth_year gender homeworld
##   <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr>  <chr>    
## 1 R2-D2     96    32 <NA>       white, bl~ red               33 <NA>   Naboo    
## 2 R5-D4     97    32 <NA>       white, red red               NA <NA>   Tatooine 
## 3 Yoda      66    17 white      green      brown            896 male   <NA>     
## 4 Wick~     88    20 brown      brown      brown              8 male   Endor    
## 5 Dud ~     94    45 none       blue, grey yellow            NA male   Vulpter  
## 6 Ratt~     79    15 none       grey, blue unknown           NA male   Aleen Mi~
## 7 R4-P~     96    NA none       silver, r~ red, blue         NA female <NA>     
## # ... with 4 more variables: species <chr>, films <list>, vehicles <list>,
## #   starships <list>

Or we could do even more advanced filtering, such as by filter for observations 1 SD above the average height:

starwars %>% 
  filter(height > mean(height, na.rm = TRUE) + sd(height, na.rm = TRUE)) # don't forget na.rm!
## # A tibble: 7 x 13
##   name  height  mass hair_color skin_color eye_color birth_year gender homeworld
##   <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr>  <chr>    
## 1 Chew~    228   112 brown      unknown    blue             200 male   Kashyyyk 
## 2 Roos~    224    82 none       grey       orange            NA male   Naboo    
## 3 Yara~    264    NA none       white      yellow            NA male   Quermia  
## 4 Lama~    229    88 none       grey       black             NA male   Kamino   
## 5 Taun~    213    NA none       grey       black             NA female Kamino   
## 6 Grie~    216   159 none       brown, wh~ green, y~         NA male   Kalee    
## 7 Tarf~    234   136 brown      brown      blue              NA male   Kashyyyk 
## # ... with 4 more variables: species <chr>, films <list>, vehicles <list>,
## #   starships <list>

Speaking of NAs, let’s see which characters have missing mass by filtering for rows where mass is NA.

starwars %>% 
  filter(mass == NA)

It give us an empty df. What happened? NA is a special case when it comes to logical filtering. A value can’t equal NA, it is NA. This is a subtle distinction. I try to remember it by reminding myself that an unknown could be equal to anything, but it definitely is an unknown.

So, if we want to filter for NAs, we have to use is.na(), which returns TRUE if an entry is NA. Let’s try to get characters with missing mass again:

starwars %>% 
  filter(is.na(mass)) # note you wrap the variable in is.na()
## # A tibble: 28 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Wilh~    180    NA auburn, g~ fair       blue              64 male  
##  2 Mon ~    150    NA auburn     fair       blue              48 female
##  3 Arve~     NA    NA brown      fair       brown             NA male  
##  4 Fini~    170    NA blond      fair       blue              91 male  
##  5 Rugo~    206    NA none       green      orange            NA male  
##  6 Ric ~    183    NA brown      fair       blue              NA male  
##  7 Watto    137    NA black      blue, grey yellow            NA male  
##  8 Quar~    183    NA black      dark       brown             62 male  
##  9 Shmi~    163    NA black      fair       brown             72 female
## 10 Bib ~    180    NA none       pale       pink              NA male  
## # ... with 18 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

To get the values that aren’t missing, you have to put a ! before is.na(), so it looks like !is.na(variable). Let’s get every observation that isn’t mising on mass:

starwars %>% 
  filter(!is.na(mass))
## # A tibble: 59 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 49 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

This works because ! converts a logical value to its opposite:

!TRUE
## [1] FALSE
!FALSE
## [1] TRUE
! 5 == 5
## [1] FALSE
! 5 == 4
## [1] TRUE

4.2.2 Filter with multiple conditions

Recall that we can combine conditions using & or |. For example, we could get observations 1 SD above the mean of height and below the mean of mass

starwars %>% 
  filter(height > mean(height, na.rm = TRUE) + sd(height, na.rm = TRUE) &
         mass < mean(mass, na.rm = TRUE))
## # A tibble: 2 x 13
##   name  height  mass hair_color skin_color eye_color birth_year gender homeworld
##   <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr>  <chr>    
## 1 Roos~    224    82 none       grey       orange            NA male   Naboo    
## 2 Lama~    229    88 none       grey       black             NA male   Kamino   
## # ... with 4 more variables: species <chr>, films <list>, vehicles <list>,
## #   starships <list>

We could get observations either 1 SD above or below the mean of height too:

  starwars %>% 
  filter(height > mean(height, na.rm = TRUE) + sd(height, na.rm = TRUE) |
         height < mean(height, na.rm = TRUE) + sd(height, na.rm = TRUE))
## # A tibble: 81 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 71 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

You can also filter based on character variables. For example, we could get ever character grey hair:

starwars %>% 
  filter(hair_color == "grey")
## # A tibble: 1 x 13
##   name  height  mass hair_color skin_color eye_color birth_year gender homeworld
##   <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr>  <chr>    
## 1 Palp~    170    75 grey       pale       yellow            82 male   Naboo    
## # ... with 4 more variables: species <chr>, films <list>, vehicles <list>,
## #   starships <list>

Or characters that have grey or brown hair:

starwars %>% 
  filter(hair_color == "grey" |
         hair_color == "brown")
## # A tibble: 19 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Leia~    150    49 brown      light      brown             19 female
##  2 Beru~    165    75 brown      light      blue              47 female
##  3 Chew~    228   112 brown      unknown    blue             200 male  
##  4 Han ~    180    80 brown      fair       brown             29 male  
##  5 Wedg~    170    77 brown      fair       hazel             21 male  
##  6 Jek ~    180   110 brown      fair       blue              NA male  
##  7 Palp~    170    75 grey       pale       yellow            82 male  
##  8 Arve~     NA    NA brown      fair       brown             NA male  
##  9 Wick~     88    20 brown      brown      brown              8 male  
## 10 Qui-~    193    89 brown      fair       blue              92 male  
## 11 Ric ~    183    NA brown      fair       blue              NA male  
## 12 Cordé    157    NA brown      light      brown             NA female
## 13 Clie~    183    NA brown      fair       blue              82 male  
## 14 Dormé    165    NA brown      light      brown             NA female
## 15 Tarf~    234   136 brown      brown      blue              NA male  
## 16 Raym~    188    79 brown      light      brown             NA male  
## 17 Rey       NA    NA brown      light      hazel             NA female
## 18 Poe ~     NA    NA brown      light      brown             NA male  
## 19 Padm~    165    45 brown      light      brown             46 female
## # ... with 5 more variables: homeworld <chr>, species <chr>, films <list>,
## #   vehicles <list>, starships <list>

Or characters that don’t have brown hair:

starwars %>% 
  filter(hair_color != "brown")
## # A tibble: 64 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172  77   blond      fair       blue            19   male  
##  2 Dart~    202 136   none       white      yellow          41.9 male  
##  3 Owen~    178 120   brown, gr~ light      blue            52   male  
##  4 Bigg~    183  84   black      light      brown           24   male  
##  5 Obi-~    182  77   auburn, w~ fair       blue-gray       57   male  
##  6 Anak~    188  84   blond      fair       blue            41.9 male  
##  7 Wilh~    180  NA   auburn, g~ fair       blue            64   male  
##  8 Yoda      66  17   white      green      brown          896   male  
##  9 Palp~    170  75   grey       pale       yellow          82   male  
## 10 Boba~    183  78.2 black      fair       brown           31.5 male  
## # ... with 54 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

You may be wandering if there is some way to extract those observations that have “grey” listed as one of several colors.

It’s a little tricky, but it can be done by using the stringr function str_detect(). Time permitting, we’ll cover stringr in a bit more detail tomorrow, but str_detect() can be used to look for a string in an object; it returns a logical (TRUE or FALSE) based on whether or not the string is found in that object. It is a lot like grep() which we saw earlier, but has the string/data as its first argument (a la tidyverse convention). Let’s use it in combination with filter() to get these salt & pepper starwars characters:

starwars %>% 
  filter(str_detect(hair_color, "grey")) # first argument is string var,
## # A tibble: 3 x 13
##   name  height  mass hair_color skin_color eye_color birth_year gender homeworld
##   <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr>  <chr>    
## 1 Owen~    178   120 brown, gr~ light      blue              52 male   Tatooine 
## 2 Wilh~    180    NA auburn, g~ fair       blue              64 male   Eriadu   
## 3 Palp~    170    75 grey       pale       yellow            82 male   Naboo    
## # ... with 4 more variables: species <chr>, films <list>, vehicles <list>,
## #   starships <list>
                       # followed by pattern it looks for

Since str_detect() returns a logical, we can negate it with ! to get the opposite (observations that don’t contain the string "grey" in hair_color):

starwars %>% 
  filter(!str_detect(hair_color, "grey"))
## # A tibble: 79 x 13
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 Dart~    202   136 none       white      yellow          41.9 male  
##  3 Leia~    150    49 brown      light      brown           19   female
##  4 Beru~    165    75 brown      light      blue            47   female
##  5 Bigg~    183    84 black      light      brown           24   male  
##  6 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
##  7 Anak~    188    84 blond      fair       blue            41.9 male  
##  8 Chew~    228   112 brown      unknown    blue           200   male  
##  9 Han ~    180    80 brown      fair       brown           29   male  
## 10 Wedg~    170    77 brown      fair       hazel           21   male  
## # ... with 69 more rows, and 5 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>

Exercise 4.2a

Starting with the starwars data frame, filter for characters thats birth year is at least 200. Select just their name, species, and birth_year.

Exercise 4.2b

Starting with the starwars data frame, filter for characters that don’t have blue in their eye color (hint: it could have more than one color) and print their name, eye_color, and species.

Exercise 4.2c

Starting with the starwars data frame, filter for droids from Tatooine or humans from Naboo. Select just name, homeworld, species, hair, eye, and skin color and make sure the columns in that order.

4.3 Transforming data with mutate() and transmute()

The next verbs from dplyr we’ll discuss are mutate() and transmute(). mutate() is for adding columns to a dataframe. transmute() is for replacing columns in a dataframe. Let’s start with mutate()

4.3.1 mutate()

Recall from last time that we can add columns to a dataframe in base R using data$new_col <-. For example, we could add height in meters to our starwars data:

starwars$height_in_m = starwars$height/100

starwars 
## # A tibble: 87 x 14
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 6 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_m <dbl>
# cleaning it back up
starwars <- starwars %>% 
  select(-height_in_m)

In the tidyverse, we use mutate() instead. mutate() requires data as its first argument, followed by a set of expressions defining new columns, separated by a comma. For example, we could calculate height in meters and millimeters:

starwars <- starwars %>% 
  mutate(height_in_mm = height*10, # height in millimeters
         height_in_m = height/100) # height in meters

mutate() performs each calculation in order, so you can use variables created earlier within the same mutate call in later operations. For example, let’s z score height and mass (using the base R function scale()) and then average them together using the base R function rowMeans():

starwars %>% 
  mutate(height_z = scale(height),
         mass_z = scale(mass),
         height_mass_z = rowMeans(data.frame(height_z, mass_z), na.rm = TRUE))
## # A tibble: 87 x 18
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 10 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>, height_z[,1] <dbl>, mass_z[,1] <dbl>,
## #   height_mass_z <dbl>

As you can see, getting row means (i.e., mean for each row across a set of columns) can be a little clunky in mutate(). The rowwise() function is designed to make this easier. To use it, we call it before a mutate() call. Let’s try it

starwars %>% 
  rowwise() %>% 
  mutate(height_z = scale(height),
         mass_z = scale(mass),
         height_mass_z = mean(c(height_z, mass_z), na.rm = TRUE))
## Source: local data frame [87 x 18]
## Groups: <by row>
## 
## # A tibble: 87 x 18
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 10 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>, height_z <dbl>, mass_z <dbl>, height_mass_z <dbl>

Oops, as you can see we got NaN, because it’s trying to get z scores for each row, which are not defined. We would need to do two mutate calls and use the rowwise() function between them:

starwars %>% 
  mutate(height_z = scale(height),
         mass_z = scale(mass)) %>% 
  rowwise() %>% 
  mutate(height_mass_z = mean(c(height_z, mass_z), na.rm = TRUE))
## Source: local data frame [87 x 18]
## Groups: <by row>
## 
## # A tibble: 87 x 18
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 10 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>, height_z[,1] <dbl>, mass_z[,1] <dbl>,
## #   height_mass_z <dbl>

You can overwrite columns with mutate(). For example, gender is currently a character, but we could turn it using mutate to overwrite it:

starwars %>%
  mutate(gender = factor(gender))
## # A tibble: 87 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <fct> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

4.3.2 transmute()

transmute() is similar to mutate, but instead of returning the original data frame with the new (additional) columns, it returns just the new columns. For example, we could use transmute if we just wanted a dataframe of z scored height and mass:

starwars %>% 
  transmute(height_z = scale(height),
            mass_z = scale(mass))
## # A tibble: 87 x 2
##    height_z[,1] mass_z[,1]
##           <dbl>      <dbl>
##  1      -0.0678    -0.120 
##  2      -0.212     -0.132 
##  3      -2.25      -0.385 
##  4       0.795      0.228 
##  5      -0.701     -0.285 
##  6       0.105      0.134 
##  7      -0.269     -0.132 
##  8      -2.22      -0.385 
##  9       0.249     -0.0786
## 10       0.220     -0.120 
## # ... with 77 more rows

Note that this basically equivalent to doing a mutate() followed by a select() for the newly mutated columns.

Exercise 4.3a

Create a new variable called bmi that is each character’s bmi. bmi = kg / m^2. Mass is already in kg units, but height is currently in cm units, so height will need to be converted (1m = 100cm).

Exercise 4.3b

This time, do the same thing, but use transmute so that the resulting dataframe has just name, height in meters, mass, and bmi (hint: you can always mutate or transmute a variable to be equal to itself)

4.4 Grouping Data with group_by()

group_by() is another dplyr function that creates groups based on one or more variables in the data. This affects all kinds of things that you then do with the data, such as mutating. It is pretty simple to use. It requires data as its first argument, and the you name the variables (unquoted) to group by separated by a column.

For example, we could group our starwars data by characters’ homeworld:

starwars %>% 
  group_by(homeworld)
## # A tibble: 87 x 15
## # Groups:   homeworld [49]
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

Okay, by the looks of it, nothing happened. But, if we paste it into the console, you can see that it did change something. It adds some meta-data saying that homeworld is a grouping factor, but that is it.

But, it has powerful effects on how other functions interact with our grouped dataset. Let’s see what happens when we take the mean mass with and without grouping:

starwars %>% 
  mutate(mean_mass = mean(mass, na.rm = TRUE)) %>% 
  select(homeworld, mean_mass, everything()) # re-arrange for easy viewing
## # A tibble: 87 x 16
##    homeworld mean_mass name  height  mass hair_color skin_color eye_color
##    <chr>         <dbl> <chr>  <int> <dbl> <chr>      <chr>      <chr>    
##  1 Tatooine       97.3 Luke~    172    77 blond      fair       blue     
##  2 Tatooine       97.3 C-3PO    167    75 <NA>       gold       yellow   
##  3 Naboo          97.3 R2-D2     96    32 <NA>       white, bl~ red      
##  4 Tatooine       97.3 Dart~    202   136 none       white      yellow   
##  5 Alderaan       97.3 Leia~    150    49 brown      light      brown    
##  6 Tatooine       97.3 Owen~    178   120 brown, gr~ light      blue     
##  7 Tatooine       97.3 Beru~    165    75 brown      light      blue     
##  8 Tatooine       97.3 R5-D4     97    32 <NA>       white, red red      
##  9 Tatooine       97.3 Bigg~    183    84 black      light      brown    
## 10 Stewjon        97.3 Obi-~    182    77 auburn, w~ fair       blue-gray
## # ... with 77 more rows, and 8 more variables: birth_year <dbl>, gender <chr>,
## #   species <chr>, films <list>, vehicles <list>, starships <list>,
## #   height_in_mm <dbl>, height_in_m <dbl>

Now, let’s see what happens if we group_by() first:

starwars %>% 
  group_by(homeworld) %>% 
  mutate(mean_mass = mean(mass, na.rm = TRUE)) %>% 
  select(homeworld, mean_mass, everything())
## # A tibble: 87 x 16
## # Groups:   homeworld [49]
##    homeworld mean_mass name  height  mass hair_color skin_color eye_color
##    <chr>         <dbl> <chr>  <int> <dbl> <chr>      <chr>      <chr>    
##  1 Tatooine       85.4 Luke~    172    77 blond      fair       blue     
##  2 Tatooine       85.4 C-3PO    167    75 <NA>       gold       yellow   
##  3 Naboo          64.2 R2-D2     96    32 <NA>       white, bl~ red      
##  4 Tatooine       85.4 Dart~    202   136 none       white      yellow   
##  5 Alderaan       64   Leia~    150    49 brown      light      brown    
##  6 Tatooine       85.4 Owen~    178   120 brown, gr~ light      blue     
##  7 Tatooine       85.4 Beru~    165    75 brown      light      blue     
##  8 Tatooine       85.4 R5-D4     97    32 <NA>       white, red red      
##  9 Tatooine       85.4 Bigg~    183    84 black      light      brown    
## 10 Stewjon        77   Obi-~    182    77 auburn, w~ fair       blue-gray
## # ... with 77 more rows, and 8 more variables: birth_year <dbl>, gender <chr>,
## #   species <chr>, films <list>, vehicles <list>, starships <list>,
## #   height_in_mm <dbl>, height_in_m <dbl>

You can also group by multiple factors, which you can just add as comma-separated unquoted variable names. For example, let’s group by homeworld and species and get the average mass:

starwars %>% 
  group_by(homeworld, species) %>% 
  mutate(mean_mass = mean(mass, na.rm = TRUE)) %>% 
  select(homeworld, mean_mass, everything())
## # A tibble: 87 x 16
## # Groups:   homeworld, species [58]
##    homeworld mean_mass name  height  mass hair_color skin_color eye_color
##    <chr>         <dbl> <chr>  <int> <dbl> <chr>      <chr>      <chr>    
##  1 Tatooine       96   Luke~    172    77 blond      fair       blue     
##  2 Tatooine       53.5 C-3PO    167    75 <NA>       gold       yellow   
##  3 Naboo          32   R2-D2     96    32 <NA>       white, bl~ red      
##  4 Tatooine       96   Dart~    202   136 none       white      yellow   
##  5 Alderaan       64   Leia~    150    49 brown      light      brown    
##  6 Tatooine       96   Owen~    178   120 brown, gr~ light      blue     
##  7 Tatooine       96   Beru~    165    75 brown      light      blue     
##  8 Tatooine       53.5 R5-D4     97    32 <NA>       white, red red      
##  9 Tatooine       96   Bigg~    183    84 black      light      brown    
## 10 Stewjon        77   Obi-~    182    77 auburn, w~ fair       blue-gray
## # ... with 77 more rows, and 8 more variables: birth_year <dbl>, gender <chr>,
## #   species <chr>, films <list>, vehicles <list>, starships <list>,
## #   height_in_mm <dbl>, height_in_m <dbl>

Exercise 4.4a

Create two new variables called species_mean_mass that is equal to the average mass per species, and species_centered_mass that is equal to each character’s mass minus their species’ mean (i.e., center mass within species). Select name, species, and all of the mass variables.

4.5 Summarizing data with summarize()

The next dplyr verb we’ll cover is summarize(), which is used to summarize across rows of a dataset. It, like all tidyverse functions, requires data as its first argument, and then you enter your summary formulas separated by commas; it looks pretty similar to mutate() and transmute(). The outcoming dataset will have just the variables you summarized and lose everything else.

Just like in mutate(), each expression is new_var_name = EXPRESSION.

Let’s use summarize on the starwars dataset to get the mean mass across all observations:

starwars %>% 
  summarize(mean_mass = mean(mass, na.rm = TRUE))
## # A tibble: 1 x 1
##   mean_mass
##       <dbl>
## 1      97.3

We can also add some more summary statistis. For example, let’s get the sd and n as well:

starwars %>% 
  summarize(mean_mass = mean(mass, na.rm = TRUE),
            sd_mass = sd(mass, na.rm = TRUE),
            n = n())
## # A tibble: 1 x 3
##   mean_mass sd_mass     n
##       <dbl>   <dbl> <int>
## 1      97.3    169.    87

4.5.1 Combining group_by() and summarize()

group_by() and summarize() can be combined to get group-level statistics. This is a great way to make tables of descriptive stats in R or to create aggregated datasets for some purposes.

To use these together, you just run group_by() followed by summarize() in a pipeline. Let’s take a look at the mass statistics per species:

starwars %>% 
  group_by(species) %>% # just add the group_by() call
  summarize(mean_mass = mean(mass, na.rm = TRUE),
            sd_mass = sd(mass, na.rm = TRUE),
            n = n())
## # A tibble: 38 x 4
##    species   mean_mass sd_mass     n
##    <chr>         <dbl>   <dbl> <int>
##  1 Aleena         15      NA       1
##  2 Besalisk      102      NA       1
##  3 Cerean         82      NA       1
##  4 Chagrian      NaN      NA       1
##  5 Clawdite       55      NA       1
##  6 Droid          69.8    51.0     5
##  7 Dug            40      NA       1
##  8 Ewok           20      NA       1
##  9 Geonosian      80      NA       1
## 10 Gungan         74      11.3     3
## # ... with 28 more rows

Let’s clean that up a bit by filtering out species with just 1 observation:

starwars %>% 
  group_by(species) %>% # just add the group_by() call
  summarize(mean_mass = mean(mass, na.rm = TRUE),
            sd_mass = sd(mass, na.rm = TRUE),
            n = n()) %>% 
  filter(n > 1)
## # A tibble: 9 x 4
##   species  mean_mass sd_mass     n
##   <chr>        <dbl>   <dbl> <int>
## 1 Droid         69.8   51.0      5
## 2 Gungan        74     11.3      3
## 3 Human         82.8   19.4     35
## 4 Kaminoan      88     NA        2
## 5 Mirialan      53.1    4.38     2
## 6 Twi'lek       55     NA        2
## 7 Wookiee      124     17.0      2
## 8 Zabrak        80     NA        2
## 9 <NA>          48     NA        5

Of course you can use multiple groups in group_by() to get crosstabs:

starwars %>% 
  group_by(species, gender) %>% # just change the group_by() call
  summarize(mean_mass = mean(mass, na.rm = TRUE),
            sd_mass = sd(mass, na.rm = TRUE),
            n = n()) %>% 
  filter(n > 1)
## # A tibble: 10 x 5
## # Groups:   species [7]
##    species  gender mean_mass sd_mass     n
##    <chr>    <chr>      <dbl>   <dbl> <int>
##  1 Droid    none       140     NA        2
##  2 Droid    <NA>        46.3   24.8      3
##  3 Gungan   male        74     11.3      3
##  4 Human    female      56.3   16.3      9
##  5 Human    male        87.0   16.5     26
##  6 Mirialan female      53.1    4.38     2
##  7 Wookiee  male       124     17.0      2
##  8 Zabrak   male        80     NA        2
##  9 <NA>     female      48     NA        3
## 10 <NA>     male       NaN    NaN        2

Exercise 4.5a

Returning to the ps_data, get the total number correct (call it num_correct), the total number of item/condition combinations (call it num_trials), and the proportion correct (call it prop_correct) for each condition and item using group_by and summarize.

4.6 Brief Overview of Other dpyr verbs

I wanted to tell you quickly about some other useful dplyr verbs we don’t have time to go into depth with, but that are useful to know about.

4.6.1 arrange()

Arrange can be used to re-arrange the rows of a dataset based on some variable(s) values. It requires the data, then each variable you want to arrange the data by separated by a comma.

For example, we can arrange the data by mass:

starwars %>% 
  arrange(mass)
## # A tibble: 87 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Ratt~     79    15 none       grey, blue unknown           NA male  
##  2 Yoda      66    17 white      green      brown            896 male  
##  3 Wick~     88    20 brown      brown      brown              8 male  
##  4 R2-D2     96    32 <NA>       white, bl~ red               33 <NA>  
##  5 R5-D4     97    32 <NA>       white, red red               NA <NA>  
##  6 Sebu~    112    40 none       grey, red  orange            NA male  
##  7 Dud ~     94    45 none       blue, grey yellow            NA male  
##  8 Padm~    165    45 brown      light      brown             46 female
##  9 Wat ~    193    48 none       green, gr~ unknown           NA male  
## 10 Sly ~    178    48 none       pale       white             NA female
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

You can make it descending order by wrapping the variable in desc():

starwars %>% 
  arrange(desc(mass))
## # A tibble: 87 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Jabb~    175  1358 <NA>       green-tan~ orange         600   herma~
##  2 Grie~    216   159 none       brown, wh~ green, y~       NA   male  
##  3 IG-88    200   140 none       metal      red             15   none  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Tarf~    234   136 brown      brown      blue            NA   male  
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Bossk    190   113 none       green      red             53   male  
##  8 Chew~    228   112 brown      unknown    blue           200   male  
##  9 Jek ~    180   110 brown      fair       blue            NA   male  
## 10 Dext~    198   102 none       brown      yellow          NA   male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

And, you can provide multiple variables to sort on, and it will do each in order:

starwars %>% 
  arrange(height, mass)
## # A tibble: 87 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Yoda      66    17 white      green      brown            896 male  
##  2 Ratt~     79    15 none       grey, blue unknown           NA male  
##  3 Wick~     88    20 brown      brown      brown              8 male  
##  4 Dud ~     94    45 none       blue, grey yellow            NA male  
##  5 R2-D2     96    32 <NA>       white, bl~ red               33 <NA>  
##  6 R4-P~     96    NA none       silver, r~ red, blue         NA female
##  7 R5-D4     97    32 <NA>       white, red red               NA <NA>  
##  8 Sebu~    112    40 none       grey, red  orange            NA male  
##  9 Gasg~    122    NA none       white, bl~ black             NA male  
## 10 Watto    137    NA black      blue, grey yellow            NA male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

If you tell it to arrange by a character variable, it will order them alphabetically:

starwars %>% 
  arrange(name)
## # A tibble: 87 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Ackb~    180    83 none       brown mot~ orange          41   male  
##  2 Adi ~    184    50 none       dark       blue            NA   female
##  3 Anak~    188    84 blond      fair       blue            41.9 male  
##  4 Arve~     NA    NA brown      fair       brown           NA   male  
##  5 Ayla~    178    55 none       blue       hazel           48   female
##  6 Bail~    191    NA black      tan        brown           67   male  
##  7 Barr~    166    50 black      yellow     blue            40   female
##  8 BB8       NA    NA none       none       black           NA   none  
##  9 Ben ~    163    65 none       grey, gre~ orange          NA   male  
## 10 Beru~    165    75 brown      light      blue            47   female
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

4.6.2 rename()

rename() can be used to rename variables. It requires data as its first argument, then the rename expressions in the form new_name = old_name. For example, we could rename name from the starwars data:

starwars %>% 
  rename(char_name = name)
## # A tibble: 87 x 15
##    char_name height  mass hair_color skin_color eye_color birth_year gender
##    <chr>      <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke Sky~    172    77 blond      fair       blue            19   male  
##  2 C-3PO        167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2         96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Darth Va~    202   136 none       white      yellow          41.9 male  
##  5 Leia Org~    150    49 brown      light      brown           19   female
##  6 Owen Lars    178   120 brown, gr~ light      blue            52   male  
##  7 Beru Whi~    165    75 brown      light      blue            47   female
##  8 R5-D4         97    32 <NA>       white, red red             NA   <NA>  
##  9 Biggs Da~    183    84 black      light      brown           24   male  
## 10 Obi-Wan ~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

And, you can provide multiple renames:

starwars %>% 
  rename(char_name = name,
         height_cm = height,
         mass_kg = mass)
## # A tibble: 87 x 15
##    char_name height_cm mass_kg hair_color skin_color eye_color birth_year gender
##    <chr>         <int>   <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke Sky~       172      77 blond      fair       blue            19   male  
##  2 C-3PO           167      75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2            96      32 <NA>       white, bl~ red             33   <NA>  
##  4 Darth Va~       202     136 none       white      yellow          41.9 male  
##  5 Leia Org~       150      49 brown      light      brown           19   female
##  6 Owen Lars       178     120 brown, gr~ light      blue            52   male  
##  7 Beru Whi~       165      75 brown      light      blue            47   female
##  8 R5-D4            97      32 <NA>       white, red red             NA   <NA>  
##  9 Biggs Da~       183      84 black      light      brown           24   male  
## 10 Obi-Wan ~       182      77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

4.6.3 *_join()

dplyr has some useful functions for joining datasets together based on a unique key (or set of key variables) to match on. For example, if we had a dataset called lightsabers that has various starwars characters’ lightsaber colors:

lightsabers <- data.frame(name = c("Luke Skywalker", 
                                   "Darth Vader", 
                                   "Obi-Wan Kenobi", 
                                   "Dooku"),
                          lightsaber_color = c("green", 
                                               "red", 
                                               "blue", 
                                               "red"))

We could join this to our starwars data using one of the join functions, such as left_join(), which keeps everythin in the left hand dataset (the first datatset in the arguments) and only records that match in the right hand dataset:

left_join(starwars,
          lightsabers)
## Joining, by = "name"
## # A tibble: 87 x 16
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue            19   male  
##  2 C-3PO    167    75 <NA>       gold       yellow         112   <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red             33   <NA>  
##  4 Dart~    202   136 none       white      yellow          41.9 male  
##  5 Leia~    150    49 brown      light      brown           19   female
##  6 Owen~    178   120 brown, gr~ light      blue            52   male  
##  7 Beru~    165    75 brown      light      blue            47   female
##  8 R5-D4     97    32 <NA>       white, red red             NA   <NA>  
##  9 Bigg~    183    84 black      light      brown           24   male  
## 10 Obi-~    182    77 auburn, w~ fair       blue-gray       57   male  
## # ... with 77 more rows, and 8 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>, lightsaber_color <chr>

And let’s see what happens if we reverse the order:

left_join(lightsabers,
          starwars)
## Joining, by = "name"
##             name lightsaber_color height mass    hair_color skin_color
## 1 Luke Skywalker            green    172   77         blond       fair
## 2    Darth Vader              red    202  136          none      white
## 3 Obi-Wan Kenobi             blue    182   77 auburn, white       fair
## 4          Dooku              red    193   80         white       fair
##   eye_color birth_year gender homeworld species
## 1      blue       19.0   male  Tatooine   Human
## 2    yellow       41.9   male  Tatooine   Human
## 3 blue-gray       57.0   male   Stewjon   Human
## 4     brown      102.0   male   Serenno   Human
##                                                                                                                    films
## 1                        Revenge of the Sith, Return of the Jedi, The Empire Strikes Back, A New Hope, The Force Awakens
## 2                                           Revenge of the Sith, Return of the Jedi, The Empire Strikes Back, A New Hope
## 3 Attack of the Clones, The Phantom Menace, Revenge of the Sith, Return of the Jedi, The Empire Strikes Back, A New Hope
## 4                                                                              Attack of the Clones, Revenge of the Sith
##                             vehicles
## 1 Snowspeeder, Imperial Speeder Bike
## 2                                   
## 3                    Tribubble bongo
## 4                   Flitknot speeder
##                                                                                                  starships
## 1                                                                                 X-wing, Imperial shuttle
## 2                                                                                          TIE Advanced x1
## 3 Jedi starfighter, Trade Federation cruiser, Naboo star skiff, Jedi Interceptor, Belbullab-22 starfighter
## 4                                                                                                         
##   height_in_mm height_in_m
## 1         1720        1.72
## 2         2020        2.02
## 3         1820        1.82
## 4         1930        1.93

There are also more complicated joins that you can learn more about in Ch. 13 of R for Data Science

4.6.4 distinct()

distinct() can be used to get distinct entries within a dataset. It requires data as its first argument, and then variables you want to be distinct. Let’s start with just one variable, distinct homeworlds in starwars:

starwars %>% 
  distinct(homeworld)
## # A tibble: 49 x 1
##    homeworld 
##    <chr>     
##  1 Tatooine  
##  2 Naboo     
##  3 Alderaan  
##  4 Stewjon   
##  5 Eriadu    
##  6 Kashyyyk  
##  7 Corellia  
##  8 Rodia     
##  9 Nal Hutta 
## 10 Bestine IV
## # ... with 39 more rows

You can also get distinct combination by supplying more than 1 variable:

starwars %>% 
  distinct(homeworld, species)
## # A tibble: 58 x 2
##    homeworld species
##    <chr>     <chr>  
##  1 Tatooine  Human  
##  2 Tatooine  Droid  
##  3 Naboo     Droid  
##  4 Alderaan  Human  
##  5 Stewjon   Human  
##  6 Eriadu    Human  
##  7 Kashyyyk  Wookiee
##  8 Corellia  Human  
##  9 Rodia     Rodian 
## 10 Nal Hutta Hutt   
## # ... with 48 more rows

Note that by default it give us just the variables included in the distinct() call. We can change this by changing the .keep_all argument to TRUE:

starwars %>% 
  distinct(homeworld, species, .keep_all = TRUE)
## # A tibble: 58 x 15
##    name  height  mass hair_color skin_color eye_color birth_year gender
##    <chr>  <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> 
##  1 Luke~    172    77 blond      fair       blue              19 male  
##  2 C-3PO    167    75 <NA>       gold       yellow           112 <NA>  
##  3 R2-D2     96    32 <NA>       white, bl~ red               33 <NA>  
##  4 Leia~    150    49 brown      light      brown             19 female
##  5 Obi-~    182    77 auburn, w~ fair       blue-gray         57 male  
##  6 Wilh~    180    NA auburn, g~ fair       blue              64 male  
##  7 Chew~    228   112 brown      unknown    blue             200 male  
##  8 Han ~    180    80 brown      fair       brown             29 male  
##  9 Gree~    173    74 <NA>       green      black             44 male  
## 10 Jabb~    175  1358 <NA>       green-tan~ orange           600 herma~
## # ... with 48 more rows, and 7 more variables: homeworld <chr>, species <chr>,
## #   films <list>, vehicles <list>, starships <list>, height_in_mm <dbl>,
## #   height_in_m <dbl>

4.6.5 count()

count() is an easy way to get the count of a variable in a dataset. It’s basically a shortcut of group_by() and summarize(n = n()). It requires data as its first argument, then the variables you want counts of. For example, let’s get counts of species in starwars:

starwars %>%
  count(species)
## # A tibble: 38 x 2
##    species       n
##    <chr>     <int>
##  1 Aleena        1
##  2 Besalisk      1
##  3 Cerean        1
##  4 Chagrian      1
##  5 Clawdite      1
##  6 Droid         5
##  7 Dug           1
##  8 Ewok          1
##  9 Geonosian     1
## 10 Gungan        3
## # ... with 28 more rows

You can also get counts of combinations of variables by adding more variables, separated by a comma:

starwars %>% 
  count(species, homeworld) %>% 
  arrange(desc(n))
## # A tibble: 58 x 3
##    species  homeworld     n
##    <chr>    <chr>     <int>
##  1 Human    Tatooine      8
##  2 Human    Naboo         5
##  3 Human    <NA>          5
##  4 Gungan   Naboo         3
##  5 Human    Alderaan      3
##  6 Droid    Tatooine      2
##  7 Droid    <NA>          2
##  8 Human    Corellia      2
##  9 Human    Coruscant     2
## 10 Kaminoan Kamino        2
## # ... with 48 more rows

Exercise 4.6a

Take the ps_data, make sure that it has only distinct kids (based on subid), but keep all of the variables. Put the dataset in order from most frequent to least frequent age.

Previous
Next