0

I have a very small csv file that when I import to R, becomes a dataframe. I would like to make this dataframe a list, but "as.list" only reads the dataframe items to me in list form and does not actually make a change to the data. I need to make a properties csv a list in order to use it to create a community in R. Any suggestions would be appreciated!

Vasan
  • 4,810
  • 4
  • 20
  • 39
Lauren
  • 1
  • Do you want the columns or rows to be in the list? If they are the columns, try something like this `iris_list <- lapply(iris, function(x) x)` – kangaroo_cliff May 12 '18 at 23:49

1 Answers1

1

Technically, a data frame is a list, with the restriction that each element of the list is of the same size. If you want to split your data frame into a list based on the row, you can use split

df_as_list <- split(df, 1:nrow(df))

This can be fancier too, it can be based on the levels of a factor or character vector:

df_as_list <- split(df, df$identifier)

Either of these will create a list of data frames, with some number of rows from the original data frame assigned to each element of the list.

Melissa Key
  • 4,476
  • 12
  • 21