Creating an R dataframe row-by-row

后端 未结 8 797
天涯浪人
天涯浪人 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

    This is a silly example of how to use do.call(rbind,) on the output of Map() [which is similar to lapply()]

    > DF <- do.call(rbind,Map(function(x) data.frame(a=x,b=x+1),x=1:3))
    > DF
      x y
    1 1 2
    2 2 3
    3 3 4
    > class(DF)
    [1] "data.frame"
    

    I use this construct quite often.

提交回复
热议问题