New Dataset with only select rows

Hello:

I'm wanting to create new datasets using only select rows.

I have a survey with row responses of "Bell", "Rogers" and "Telus"

I would like to be able to create individual datasets for each one of these row responses.

I am familiar with selecting variables in columns but not with rows.

What is the code for creating a new dataset with isolated rows? Thanks for helping out :slight_smile:

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

What is the goal here?

As an example, if I'm trying to count how many response by category:

library(tidyverse)

set.seed(201922)

df <- tibble(id = 1:10,
             resp = sample(letters[1:3], 10, replace = TRUE))
df
#> # A tibble: 10 x 2
#>       id resp 
#>    <int> <chr>
#>  1     1 a    
#>  2     2 c    
#>  3     3 b    
#>  4     4 b    
#>  5     5 c    
#>  6     6 c    
#>  7     7 c    
#>  8     8 b    
#>  9     9 c    
#> 10    10 b

df %>%
  count(resp, name = "count")
#> # A tibble: 3 x 2
#>   resp  count
#>   <chr> <int>
#> 1 a         1
#> 2 b         4
#> 3 c         5

Created on 2019-09-22 by the reprex package (v0.3.0)

#> Carrier Sepal.Width Petal.Length Petal.Width Species
#> 1 Bell 3.5 1.4 0.2 setosa
#> 2 Telus 3.0 1.4 0.2 setosa
#> 3 Rogers 3.2 1.3 0.2 setosa
#> 4 Rogers 3.1 1.5 0.2 setosa
#> 5 Telus 3.6 1.4 0.2 setosa
#> 6 Bell 3.9 1.7 0.4 setosa

How would I create a new dataset only containing responses from Bell?

Hello! Thank you for your help. The goal is to determine behaviours from Bell Consumers in isolation. I have replied to my original post providing an example. I want to create a new dataset to work with. That contains only responses of respondents who are with Bell.
Does that help?

I'm assuming you prefer base R solutions, this would be how to do it

df <- data.frame(stringsAsFactors=FALSE,
                 Carrier = c("Bell", "Telus", "Rogers", "Rogers", "Telus", "Bell"),
                 Sepal.Width = c(3.5, 3, 3.2, 3.1, 3.6, 3.9),
                 Petal.Length = c(1.4, 1.4, 1.3, 1.5, 1.4, 1.7),
                 Petal.Width = c(0.2, 0.2, 0.2, 0.2, 0.2, 0.4),
                 Species = c("setosa", "setosa", "setosa", "setosa", "setosa", "setosa")
)

df[df$Carrier == "Bell",]
#>   Carrier Sepal.Width Petal.Length Petal.Width Species
#> 1    Bell         3.5          1.4         0.2  setosa
#> 6    Bell         3.9          1.7         0.4  setosa

Please note the way I'm sharing the sample data, that is a proper way of sharing data here.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.