One liner wanted: Create data frame and give colnames: R data.frame(…, colnames = c(“a”, “b”, “c”))

后端 未结 2 2015
别跟我提以往
别跟我提以往 2020-12-11 08:01

Is there an easier (i.e. one line of code instead of two!) way to do the following:

results <- as.data.frame(str_split_fixed(c(\"SampleID_someusefulinfo.c         


        
2条回答
  •  醉酒成梦
    2020-12-11 08:24

    We can use the dimnames option in matrix as the OP was using matrix to create the data.

    data.frame(matrix(1:4, 2, 2, dimnames=list(NULL, c("a", "b"))))
    

    Or

    `colnames<-`(data.frame(matrix(1:4, 2, 2)), c('a', 'b'))
    

提交回复
热议问题