Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205491

Remove first columns of every tibble in list in R

$
0
0

I have a list with several tibbles comprising several columns; and I want to remove the first 2 columns in each tibble (not using for loop).

 #Example data with tibble and list
 w <- c(1, 2, 3, 4, 5)
 x <- c(1, 2, 3, 4, 5)
 y <- c(1, 2, 3, 4, 5)
 z <- c(1, 2, 3, 4, 5)
 tibble <- tibble(w, x, y, z)
 list <- list(tibble, tibble, tibble, tibble)

 #Remove the first 2 columns in the tibble
 tibble1 <- subset(tibble, select=-c(1:2))
 tibble1

 #Tried this to remove the first two columns of each tibble in list 
 list1 <- sapply(list, FUN = function(x) subset(x, select=-c(1:2)) ) 
 list1

Viewing all articles
Browse latest Browse all 205491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>