Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

The set up code. If it runs fine you should get a list of 5 vectors, with each vector having 800 numbers.

h5=rep(0,800);h6=h5;h7=h5;h8=h5;h9=h5
list_knot<- list(h5,h6,h7,h8,h9)
list_length <- length(list_knot) # 5 
x=seq(from=-400,to=400,length.out=800)

vec1 <- list(c(1, 2, 3, 4, 5)) # as per your requirement
list_knot <- lapply(vec1[[1]], function(v, x) x - v^3, x = 1:800)

I was wondering how I could make all of the values within list_knot that are < 0 = 0 within that function or another function?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading