使用循环填充数据框(2)

时间:2018-06-03 22:17:59

标签: loops dataframe populate

亲爱的Stack Overflow用户,

我的问题与我应该遵循的程序有关,用循环填充数据框。我知道有一些线程解决了这个问题,但它们似乎都没有对我想要解决的问题有用。基本上,我想要做的是使用循环填充以下数据框:

Dataframe <- data.frame (
Nest = NA, 
Food = NA, 
Sex = NA, 
Min.Dataframe = NA, 
Max.Dataframe = NA, 
Av.Dataframe = NA
)

所以:

使用循环填充此数据框,如下所示:

 for (i in 1:length(AllNests)){    
    Nest.i <- AllNests[i]    
    Owls.i <- Owls[Owls$Nest == Nest.i, ] 

    for (j in 1:length((AllFood))) {    
    Food.j <- AllFood[j]    
    Owls.j <- Owls.i[Owls.i$FoodTreatment==Food.j, ]

    for (k in 1:length(AllSex)){
    Sex.k <- AllSex[k]
    Owls.k <- Owls.j[Owls.j$SexParent==Sex.k, ]

     Dataframe[,1] <- Owls.k$Nest
     Dataframe[,2] <- Owls.k$FoodTreatment
     Dataframe[,3] <- Owls.k$SexParent
     Dataframe[,4] <- min(Owls.k$SiblingNegotiation)
     Dataframe[,5] <- max(Owls.k$SiblingNegotiation)
     Dataframe[,6] <- mean(Owls.k$SiblingNegotiation)   
    }
    }    
    }

感谢您阅读这篇文章,我将不胜感激,请参考以下内容, 最好,

0 个答案:

没有答案