Output a vector in R in the same format used for inputting it into R

后端 未结 2 1753
闹比i
闹比i 2020-11-30 05:53

Maybe I\'m imagining this, but I think there is a built-in R function that lets you print an R vector (and possibly other objects like matrices and data frames) in the forma

2条回答
  •  失恋的感觉
    2020-11-30 06:42

    dput maybe?

    > test <- c(1,2,3)
    > dput(test)
    c(1, 2, 3)
    

    You can also dump out multiple objects in one go to a file that is written in your working directory:

    > test2 <- matrix(1:10,nrow=2)
    > test2
         [,1] [,2] [,3] [,4] [,5]
    [1,]    1    3    5    7    9
    [2,]    2    4    6    8   10
    > dump(c("test","test2"))
    

    dumpdata.r will then contain:

    test <-
    c(1, 2, 3)
    test2 <-
    structure(1:10, .Dim = c(2L, 5L))
    

提交回复
热议问题