Well tell me how this will work for you.
Using this data:
O <- structure(list(text.1 = list(character(0), c("access", "access", "access", "access")), text.2 = list(character(0), c("report", "access", "access", "access")), text.3 = list(character(0), c("access", "access", "access", "access")), text.4 = list(character(0), c("access", "access", "access", "access")), text.5 = list(character(0), "access"), text.6 = list(character(0), character(0)), text.7 = list( character(0), c("report", "report", "access", "access", "report", "report", "report", "report", "report", "report", "data", "data", "report", "access", "report", "report" )), text.8 = list(character(0), c("report", "access", "access")), text.9 = list(character(0), "report"), text.10 = list( NULL, c("report", "access", "access", "access", "report", "access"))), .Names = c("text.1", "text.2", "text.3", "text.4", "text.5", "text.6", "text.7", "text.8", "text.9", "text.10" ))
Since it seems that words are always in the second element of text.x lists, we take these words and put them in a newlist . Moreover, we will turn this data into factors so that later it can be regrouped into a data frame.
newlist <- list() for(item in O) { newlist[[length(newlist)+1]] <- factor(item[[2]], levels = c("access", "data", "report")) } dd <- data.frame(lapply(newlist, table)) dd <- t(as.matrix(dd[,c(2,4,6,8,10,12,14,16,18,20)])) rownames(dd) <- paste0("Text.",1:10) colnames(dd) <- c("access", "data", "report") dd