Carlos Tellez
Carlos Tellez

Reputation: 157

How put Dataframe into one cell as list in R

i'm trying to put a dataframe as list in one cell in R, but when i try to do i get a warning msg and only is saved the first column

library(tidyverse)

list1 <- list(A = "A1", B = "B1", C = "C1")   # Create first example list
list1     

list2 <- list(A = "A2", B = "B2", C = "C2")   # Create second example list
list2 

list12 <- Map(c, list1, list2) %>% as.data.frame()             # Merge two lists
list12

Test_ <- "Row1" %>% as.data.frame()
Test_$list[1] <- list12

This is the error

Warning message:
In Test_$list[1] <- list12 :
  number of items to replace is not a multiple of replacement length

I want to have something like this, have a kind of subtable into my dataframe: enter image description here Thanks

Upvotes: 1

Views: 359

Answers (1)

akrun
akrun

Reputation: 887891

We can wrap with list on the object list12 which is a data.frame

Test_$list[1] <- list(list12)

Upvotes: 1

Related Questions