I am trying to reduce the size of a dataframe by removing every third column.
Here is my example dataframe:
example = data.frame(x=c(1,2,3,4), y=c(1,2,3,4), z=c(1,2,3,4), w=c(1,2,3,4), p=c(1,2,3,4), q=c(1,2,3,4), r=c(1,2,3,4))
Which looks like this
x y z w p q r
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4 4
I would like to convert it into something that looks like this
x y w p r
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
I have been able to reduce the number of rows using tidyverse:
example <- example %>% dplyr::filter(row_number() %% 3 != 1)
But I can't figure out how to delete every third column.
I have also tried to use this line:
example[, !(c%%3==0)]
from Deleting every n-th row in a dataframe but I keep getting this error: Error in c%%3 : non-numeric argument to binary operator
Thanks in advance for your help.