DSC-WAV / best-practices

Best practices for an introductory data science workshop eCOTS 2022
MIT License
2 stars 0 forks source link

professor please help #5

Open beanumber opened 2 years ago

beanumber commented 2 years ago
x <- c(3, 2, 1, 1, 4, 5, 6)

ds <- tibble(id = x) %>%
  mutate(
    x_grp = 
      case_when(
        id %in% c(1, 2, 3) ~ "sustainable",
        id == 4            ~ "experimental",
        id == c(5, 6)    ~ "fossil fuel"
      )
  )
#> Error in tibble(id = x) %>% mutate(x_grp = case_when(id %in% c(1, 2, 3) ~ : could not find function "%>%"

ds
#> Error in eval(expr, envir, enclos): object 'ds' not found

Created on 2022-05-19 by the reprex package (v2.0.1)

beanumber commented 2 years ago

OK, I did that. It still doesn't work

library(tidyverse)

x <- c(3, 2, 1, 1, 4, 5, 6)

ds <- tibble(id = x) %>%
  mutate(
    x_grp = 
      case_when(
        id %in% c(1, 2, 3) ~ "sustainable",
        id == 4            ~ "experimental",
        id == c(5, 6)    ~ "fossil fuel"
      )
  )
#> Warning in id == c(5, 6): longer object length is not a multiple of shorter
#> object length

ds
#> # A tibble: 7 × 2
#>      id x_grp       
#>   <dbl> <chr>       
#> 1     3 sustainable 
#> 2     2 sustainable 
#> 3     1 sustainable 
#> 4     1 sustainable 
#> 5     4 experimental
#> 6     5 <NA>        
#> 7     6 <NA>

Created on 2022-05-19 by the reprex package (v2.0.1)