Search code examples
rtibble

Is there a function like tail for columns in tibbles?


I have a tibble with more than 20 columns, so when I view it in the console, only 20 columns will be shown and one will be summarized below the head of the tibble even when I maximize the window.

Is there a function like tail() for columns that shows only the last n columns?


Solution

  • I believe you are looking for tidy select helper last_col() which by itself brings the last column however per the dplyr site https://tidyselect.r-lib.org/reference/everything.html you can also have an offset in this to count backwards from the last column.

    This is used with select()

    #returns second to last column
    
    mtcars%>% select(last_col(1))
    
    #pulls in last col and second to last col
    ## interesting that it is base 0
    
    mtcars%>% select(last_col(0:1))