I want to add a column at specific position in r, but mutate (xx, .before = "exisiting column) doesn't work right:
starwars %>% mutate (new_column = "Other", .before = 1)
# A tibble: 87 × 16
name height mass hair_color skin_color eye_color birth_year sex gender homeworld species films vehicles starships ICP_type .before
<chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <chr> <chr> <chr> <list> <list> <list> <chr> <dbl>
1 Luke Skywalker 172 77 blond fair blue 19 male masculine Tatooine Human <chr [5]> <chr [2]> <chr [2]> Other 1
2 C-3PO 167 75 NA gold yellow 112 none masculine Tatooine Droid <chr [6]> <chr [0]> <chr [0]> Other 1
3 R2-D2 96 32 NA white, blue red 33 none masculine Naboo Droid <chr [7]> <chr [0]> <chr [0]> Other 1
It creates a ".before" column rather than adding the new column before the first column.
I tried add_column(), and it works ok. But I still want to know why it goes wrong. Thanks!