data.frame without ruining column names

前端 未结 2 1541
借酒劲吻你
借酒劲吻你 2020-11-27 22:39

Is there a way to use data.frame without it ruining the column names?

I have following structure:

$`Canon PowerShot`
[1] 9.997803e-01 9.997318e-01 3         


        
相关标签:
2条回答
  • 2020-11-27 22:47

    You can stop R changing the names to syntatically valid names by setting check.names = FALSE. See ?data.frame for details.

    # assuming your data is in a list called my_list
    do.call(data.frame, c(my_list, check.names = FALSE))
    
    0 讨论(0)
  • 2020-11-27 22:56

    data.frames in R are actually lists. Therefore, this is also valid:

    data.frame(my_list, check.names = FALSE)
    

    Knowing this opens up the possibilities of using lapply on data.frames, which I think is pretty cool:

    my_data <- data.frame(my_list, check.names = FALSE)
    lapply(my_data, IQR)
    
    0 讨论(0)
提交回复
热议问题