-1

I have a data frame with two columns and I'm trying to assign list objects row by row to two cells (one in each column):

Type_I_Error<-c()
Type_II_Error<-c()
new_frame<-data.frame("Type_I_Error", "Type_II_Error")
new_frame <- data.frame(Type_I_Error=character(),
             Type_II_Error=character(), 
             stringsAsFactors=FALSE) 

type1errorlist <- list(character(0))
type1errorlist[[1]][length(type1errorlist[[1]]) + 1] <- "type1errors:"
type1errorlist[[1]][length(type1errorlist[[1]]) + 1] <- "2002_9"

type2errorlist <- list(character(0))
type2errorlist[[1]][length(type2errorlist[[1]]) + 1] <- "type2errors:"
type2errorlist[[1]][length(type2errorlist[[1]]) + 1] <- "2001_9"

a<-as.character(type1errorlist)
b<-as.character(type2errorlist)
new_frame <- rbind(new, c(a, b))

I get the following error: Error in rbind2(..1, r) : cannot coerce type 'closure' to vector of type 'list'

How do I fix this?

Deb Martin
  • 51
  • 12
  • Please provide code and sample data. – r2evans Jun 30 '16 at 00:22
  • I have added more sample data for the type2errorlist variable. I only posted this portion of the code because I have checked all the other lines in the function and they are working fine. – Deb Martin Jun 30 '16 at 07:04
  • ... which means you did not post enough for a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Especially with languages like R, when you ask for help you really must provide (a) self-contained code so that we aren't wondering what a variable looks like or what a function does; (b) data so we can test this code; and both of these so that (c) we know what you have tried so far. I'm not being mean or needy, I'm explaining why people who volunteer their time chose to put your question on hold: we don't have time to guess like this. – r2evans Jun 30 '16 at 13:56
  • okay, sorry about that. I pasted all my code and clarified my question, so it is reproducible now. – Deb Martin Jul 01 '16 at 09:10

1 Answers1

0

I'm not really sure what's going on here. Or why you are calling: a<-as.character(type1errorlist) but if you are trying to simply make a single data-frame, you could just append the lists together then rbind it:

do.call(rbind, append(type1errorlist, type2errorlist))

which produces, in this example, a 2x2 dataframe.

ayman
  • 1,341
  • 12
  • 22
  • I'm trying to put a list into one single cell (so I'm trying to fill in a dataframe with two columns, one column for type1errorlist and another for type2errorlist). I tried doing new_frame <- rbind(new, c(unlist(a), unlist(b))) but I still get the same error. – Deb Martin Jul 01 '16 at 21:40
  • You want to pack the whole 2x2 into one single cell? or you are trying to pack the row to one cell and have a 1-dimensional data-frame? – ayman Jul 03 '16 at 01:55
  • my dataframe has two columns, and I'm trying to fill a list in each individual cell (doing this row by row so that each column gets an entry). I'm trying to fit the entire list called "type1errorlist" into one cell under the column called Type_I_Error and the entire list called "type2errorlist" into one cell under the column Type_II_Error – Deb Martin Jul 08 '16 at 23:04
  • I'm basically not sure why using rbind to place a list into a cell is not working. I also tried setting an individual cell to a list (such as the one in the code above) but this does not work either. Any help on this would be appreciated. – Deb Martin Jul 11 '16 at 06:16