0
votes

I am trying to run the below code line to create a data frame from a list with varying sublists of different lengths as you can see in the error. Attached image shows the lists stored under (Table_match_list).

How do we bypass this, so that I would still be able to create a data frame. Any idea please.

CODELINE: content_table_df <- as.data.frame(Table_match_list)

ERROR: Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : arguments imply differing number of rows: 102, 98, 99

IMAGE: enter image description here

Thank you

1
What is your expected output?mhovd
Why do you need it to be a in data.frame? The premise of the frame is that each row is an "observation", all values on that row are associated together somehow. In your case, RonakShah's answer (that will work) converts three vectors of unrelated observations into associated observations. There is a not-small flaw in this logic. If you know that they were at one point associated like this, then I suggest you go back into whatever processing you did on it that would have reduced the lengths. If not, then projecting that presumption seems wrong.r2evans
HI, That's how the data is. Nothing is reducing the length.Bharath
Actually I need to write something in data extraction so that if the key word is not available in a page then it should print NA so that my lengths will be equal in all sublists. Table_search <- list("Table 14","Listing [0-9]","Program") Table_match_list <- sapply(Table_search, grep, x = tablelist, value = TRUE) This code loops through PDF file and searches for the key words. The difference in the length is due to unavailability of key word in a specific file.Bharath
Table_search <- list("Table 14","Listing [0-9]","Program") Table_match_list <- sapply(Table_search, grep, x = tablelist, value = TRUE)Bharath

1 Answers

0
votes

Try to get maximum length of Table_match_list and append NAs for the lists which are shorter.

n <- max(lengths(Table_match_list))
content_table_df <- type.convert(as.data.frame(sapply(Table_match_list, `[`, 1:n)), as.is = TRUE)