Home > Back-end >  Is there a way to remove elements from lists that starts with
Is there a way to remove elements from lists that starts with

Time:06-03

below is the lists. Is there way to remove elements that starts with asd ?

x1 <- list(asd1 = structure(19116, class = "Date"), asd2 = TRUE, 
           a3 = structure(19116, class = "Date"), MainNavBar = "V", 
           btnGetDWData = structure(0L, class = c("integer", "shinyActionButtonValue"
           )), sd = "Info", fd = NULL, 
           fd = NULL)

CodePudding user response:

One way

x1[!grepl("^asd",names(x1))]

CodePudding user response:

Try this ,

x1[startsWith(names(x1) , "asd")] <- NULL

CodePudding user response:

x1[grep("^asd", names(x1))] <- NULL
  •  Tags:  
  • r
  • Related