如果我有条件,将其放在应用函数内部/外部是否会显着影响运行时间,例如:
names = c("Joe", "Jen", "Bob")
if("Joe" %in% names){
lapply(1:1000000, function(y){
#Do something computationally intensive
})
}
if("Jen" %in% names){
lapply(1:1000000, function(y){
#Do something computationally intensive
})
}
相对:
lapply(1:1000000, function(y){
if("Joe" %in% names){
#Do something computationally intensive
}
if("Jen" %in% names){
#Do something computationally intensive
}
})
谢谢