R - How do I make all values within a list of vectors that are less than zero equal to 0?

Solution 1:

Another possible solution, using purrr::map:

library(tidyverse)

list_knot <- lapply(vec1[[1]], function(v, x) x - v^3, x = 1:800)

list_knot %>% 
  map(~ if_else(.x <= 0, 0, .x))

Solution 2:

I think pmax(0, .), should work, i.e.

list_knot <- lapply(vec1[[1]], function(v, x) pmax(0, x - v^3), x = 1:800)