How can I save a list to a file and read it in again (in R)?

前端 未结 2 2073
猫巷女王i
猫巷女王i 2021-02-18 18:30

I´ve estimated a model with the poLCA-package in R and want to save the starting values to a file, so I can re-estimate exactly the same model anytime.

This is a list of

2条回答
  •  旧时难觅i
    2021-02-18 19:27

    I would also suggest that you explore rlist package and the offered list.save function as it provides additional flexibility when saving lists.

    Example

    As available in documentation.

    require(rlist)
    x <- lapply(1:5,function(i) data.frame(a=i,b=i^2))
    list.save(x, 'list.rds')
    list.save(x, 'list.rdata')
    list.save(x, 'list.yaml')
    

    yaml file preview

    - a: 1
      b: 1.0
    - a: 2
      b: 4.0
    - a: 3
      b: 9.0
    - a: 4
      b: 16.0
    - a: 5
      b: 25.0
    

    You could then load list with use of the list.load function in the same package or you could read lines from the exported yaml file. You could also consider having a look at the list.select function and selecting objects from within list. Having said that, I presume that the easiest way to approach this would be simply to store/load a full list object.

提交回复
热议问题