Mutate of sequence not working

Hi

I am trying to do the following which doesn't work although the last line where I do the same calculation works. Using mutate I get an error "In Begin:End : numerical expression has 2 elements: only the first used"

library(tidyverse)
l_noga <- c(1:4)
mydata <- tibble(Begin = c(1,5), End = c(3,9)) %>% 
  mutate(freq = sum(Begin:End %in% l_noga))
# This is, however working:
sum(3:9 %in% l_noga)

CHeers
Renger

Is this what you are trying to do?

library(tidyverse)
l_noga <- c(1:4)
mydata <- tibble(Begin = c(1,5), End = c(3,9)) 

mydata %>% 
    rowwise() %>% 
    mutate(freq = sum(Begin:End %in% l_noga))
#> # A tibble: 2 x 3
#> # Rowwise: 
#>   Begin   End  freq
#>   <dbl> <dbl> <int>
#> 1     1     3     3
#> 2     5     9     0

Created on 2020-10-19 by the reprex package (v0.3.0)

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.