Replace rbind in for-loop with lapply? (2nd circle of hell)

前端 未结 2 1686
盖世英雄少女心
盖世英雄少女心 2020-12-10 08:30

I am having trouble optimising a piece of R code. The following example code should illustrate my optimisation problem:

Some initialisations and a function definitio

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 09:05

    A bit to long for comment, so I put it here: If columns is known in advance:

        myfunction <- function(frame){
        athing = 0
           if(columns == 5){
           athing = 100
           }
           else{
           athing = 1000
           }
        value[colums+1] = athing
        return(value)}
    
        apply(myframe, 2, myfunction)
    

    If columns is not given via environment, you can use:

    apply(myframe, 2, myfunction, columns) with your original myfunction definition.

提交回复
热议问题