Creating an R dataframe row-by-row

后端 未结 8 783
天涯浪人
天涯浪人 2020-11-29 15:52

I would like to construct a dataframe row-by-row in R. I\'ve done some searching, and all I came up with is the suggestion to create an empty list, keep a list index scalar,

8条回答
  •  死守一世寂寞
    2020-11-29 16:09

    One can add rows to NULL:

    df<-NULL;
    while(...){
      #Some code that generates new row
      rbind(df,row)->df
    }
    

    for instance

    df<-NULL
    for(e in 1:10) rbind(df,data.frame(x=e,square=e^2,even=factor(e%%2==0)))->df
    print(df)
    

提交回复
热议问题