設定代碼。如果它運行良好,你應該得到一個包含 5 個向量的串列,每個向量有 800 個數字。
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)
我想知道如何使 list_knot 中的所有值在該函式或另一個函式中 < 0 = 0?
uj5u.com熱心網友回復:
另一種可能的解決方案,使用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))
uj5u.com熱心網友回復:
我認為pmax(0, .),應該作業,即
list_knot <- lapply(vec1[[1]], function(v, x) pmax(0, x - v^3), x = 1:800)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420129.html
標籤:
