3

I have this data:

df <- structure(list(line = c("0302", "0304", "0305", "0306", "0318", 
                              "0334", "0335", "0480", "0481", "0307"), 
                     speaker = c("ID16.C-S","ID16.C-G", "ID16.C-I", "ID16.C-I-cp", 
                                 "ID16.C-I", "ID16.C-I", "ID16.C-I-cp", "ID16.C-I", 
                                 "ID16.C-I-cp", "ID16.C-U")), row.names = c(NA, -10L), 
                groups = structure(list(.rows = structure(list(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", "list"))), 
                                   row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame")), class = c("rowwise_df", "tbl_df", "tbl", "data.frame"))

I need to update the line numbering to obtain a continuous sequence. For some reason, this method does not change anything:

df %>%
  mutate(line = as.numeric(line),
         line = seq(min(line), length.out = length(line)))
# A tibble: 10 x 2
# Rowwise:                 <---
    line speaker    
   <dbl> <chr>      
 1   302 ID16.C-S   
 2   304 ID16.C-G   
 3   305 ID16.C-I   
 4   306 ID16.C-I-cp
 5   318 ID16.C-I   
 6   334 ID16.C-I   
 7   335 ID16.C-I-cp
 8   480 ID16.C-I   
 9   481 ID16.C-I-cp
10   307 ID16.C-U 

What's wrong here? My hunch is that the rowwise() command used earlier is still operative. How can it be deactivated?

EDIT:

ungroup() does it, like so:

df %>%
  ungroup() %>%
  mutate(line = as.numeric(line),
         line = seq(min(line), length.out = length(line)))

Thanks anyway!

Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34

0 Answers0