I have this code in R:
RdWh <- colorRampPalette(c("red", "white"))
GrWh <- colorRampPalette(c("green", "white"))
BlWh <- colorRampPalette(c("blue", "white"))
color.gradient.3 <- c(RdWh, GrWh, BlWh)
Then I want to get a vector
c(RdWh(10), GrWh(10), BlWh(10))
How to achieve this?
To avoid writing a bunch of calls to colorRampPalette(), you could put your color vectors into a list, color, and run that list through sapply(), where we can also call n = 10 on each run at the same time. Then wrap with c() to get a vector result, as desired.
color <- list(RdWh = c("red", "white"), GrWh = c("green", "white"), BlWh = c("blue", "white"))
c(sapply(color, function(x) colorRampPalette(x)(10)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With