Message-ID: <F2B9A144-F301-40E8-A050-C8B45D062883@dcn.davis.ca.us>
Date: 2020-08-19T17:27:31Z
From: Jeff Newmiller
Subject: combine filter() and select()
In-Reply-To: <cd5f4344-b9b9-3135-8fc5-8a235084804f@rgzm.de>
The whole point of dplyr primitives is to support data frames... that is, lists of columns. When you pare your data frame down to one column you are almost certainly using the wrong tool for the job.
So, sure, your code works... and it even does what you wanted in the dplyr style, but what a pointless exercise.
grep( "a", mytbl$file, value=TRUE )
On August 19, 2020 7:56:32 AM PDT, Ivan Calandra <calandra at rgzm.de> wrote:
>Dear useRs,
>
>I'm new to the tidyverse world and I need some help on basic things.
>
>I have the following tibble:
>mytbl <- structure(list(files = c("a", "b", "c", "d", "e", "f"), prop =
>1:6), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
>
>I want to subset the rows with "a" in the column "files", and keep only
>that column.
>
>So I did:
>myfile <- mytbl %>%
>? filter(grepl("a", files)) %>%
>? select(files)
>
>It works, but I believe there must be an easier way to combine filter()
>and select(), right?
>
>Thank you!
>Ivan
--
Sent from my phone. Please excuse my brevity.