0

I've imported an *.rds file via data = readRDS("file.rds").

enter image description here

enter image description here

Now I am trying to save the matrices as *.feather files. I tried write_feather("test.feather", data[1986]) which returns Error: x must be a data frame. However, write_feather("test.feather", as.data.frame(data[1986])) and write_feather("test.feather", as.data.frame(as.matrix(data[1986]))) return the same error.

How can I save the data set's subsets as *.feather files?

Stücke
  • 868
  • 3
  • 14
  • 41
  • 1
    Well, `x` *is a list*. If you want to write out individual items in that list, you need to subset your list — using `[[`, not `[`: `x[[1986L]]` will work. – Konrad Rudolph Jan 21 '22 at 16:04
  • Thank you for your comment and apologies ... first day at work :D `data[[1986]]` and `data[[1986L]]` both yield `Error in data[[1986]] : subscript out of bounds`. – Stücke Jan 21 '22 at 16:10
  • @Stücke are you able to provide a subset of your data? – user1357015 Jan 21 '22 at 16:11
  • 1
    @Stücke Right, I missed that: your list only has 28 elements. Use a smaller index, or, if these numbers are the *names* of the list, use quotes around them: `x[[1L]]` should work, as should `x[['1986']]`. And you might still require `as.data.frame` around that, depending on what the data type of the list elements is (I don’t know the `dgCMatrix` class, but it doesn’t look like it can be implicitly treated as a data.frame). – Konrad Rudolph Jan 21 '22 at 16:15
  • Yes, that works `data[["1986"]]`! Great, thank you. You want to post that as an answer? – Stücke Jan 21 '22 at 16:16

0 Answers0