Creating an R dataframe row-by-row

后端 未结 8 769
天涯浪人
天涯浪人 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条回答
  •  -上瘾入骨i
    2020-11-29 16:20

    I've found this way to create dataframe by raw without matrix.

    With automatic column name

    df<-data.frame(
            t(data.frame(c(1,"a",100),c(2,"b",200),c(3,"c",300)))
            ,row.names = NULL,stringsAsFactors = FALSE
        )
    

    With column name

    df<-setNames(
            data.frame(
                t(data.frame(c(1,"a",100),c(2,"b",200),c(3,"c",300)))
                ,row.names = NULL,stringsAsFactors = FALSE
            ), 
            c("col1","col2","col3")
        )
    

提交回复
热议问题