【发布时间】:2018-02-08 04:22:36
【问题描述】:
在创建处理传递的不同输入组合的循环时遇到问题。下面是一个非功能性示例,
funcOne <- function(input){
test <- data.frame(c = input, d = c(1:2))
return(test)
}
funcTwo <- function(input2, input2.2){
testing <- data.frame(a = input2, b = c(6:7))
testing$why <- ifelse(input2.2 == 0, testing$why <- c(1:2), testing$why <- c(3:4))
return(testing)
}
input1 <- c("ten", "four")
input2 <- c("sara", "john")
input2.2 <- c(0:1)
comboOne <- 0
comboTwo <- 0
combinations <- 0
for(i in 1:2){
comboOne[i] <- funcOne(input1[i])
comboTwo[i] <- funcTwo(input2[i], input2.2[i])
print(combinations[[i]] <- list(comboOne, comboTwo))
}
我知道上面的循环不起作用,但因此我无法理解。这正是我想要使用手头数据的目的。
根据我的理解,另外一个手头的问题 - 1 将通过 i 传递给一个数据帧,然后 2 将通过传递给第二个数据帧。
但是如果我需要组合呢?例如,对于comboTwo,我想为两个输入传递“1, 1”,我想传递“1,2”“2, 1”,“2, 2”来获取由funcTwo生成的所有数据帧组合功能。
【问题讨论】: