У меня есть список (414 элементов), который содержит другие списки различной длины (от 0 до 9). Каждый из этих подсписков имеет разное количество строк и столбцов.
Некоторые из подсписков имеют длину 1, как показано ниже, и имеют только 1 атрибут:
tables_list[[1]]
[,1] [,2]
[1,] "ID Number" "ABCD"
[2,] "Code" "1239463"
[3,] "Version" "1"
[4,] "Name" "ABC"
[5,] "Status" "Open"
[6,] "Currency" "USD"
[7,] "Average" "No"
[8,] "FX Rate" "2.47"
attr(,"caption")
[1] "5 && Introduction && NA"
Другие подсписки имеют длину 2 или выше и имеют 1 или более атрибутов, как показано ниже:
tables_list[[17]]
[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] "" "" "USD" "Balance" "Movement in" "Aggregate" "Overall" "" "Overall"
[2,] "" "" "" "brought forward" "year" "annual" "aggregate" "" "funded account"
[3,] "" "" "" "from previous" "" "information" "adjustments" "" ""
[4,] "" "" "" "year end" "" "" "" "" ""
[5,] "" "" "" "1" "2" "3" "4" "" "5"
[6,] "12" "Value 1" "" "0" "3,275,020" "3,275,020" "" "0" "3,275,020"
[7,] "13" "Value 2" "" "0" "0" "0" "" "0" "0"
[8,] "14" "Value 3" "" "0" "8,267,862" "8,267,862" "" "0" "8,267,862"
[9,] "15" "Value 4" "" "0" "(590,073,321)" "(590,073,321)" "" "0" "(590,073,321)"
[10,] "16" "Value 5" "" "0" "0" "0" "" "0" "0"
[11,] "17" "Value 6" "" "0" "0" "0" "" "0" "0"
[12,] "18" "Value 7" "" "0" "0" "0" "" "0" "0"
[13,] "19" "Value 8" "" "0" "0" "0" "" "0" "0"
[14,] "20" "Value 9" "" "0" "(459,222,782)" "(459,222,782)" "" "0" "(459,222,782)"
[[2]]
[,1] [,2] [,3] [,4]
[1,] "Theme" "Year" "Comment" "Created"
[2,] "Line 17 Column 2" "N/A" "Amounts are calculated according to recent standards" "XXXXXXXXXXXX"
[3,] "" "" "paid by XXXXXXXXXXXXX" ""
attr(,"caption")
[1] "20 && Values for year 2017 && NA"
[2] "20 && Comments for 2017 && NA"
Это мой код для присвоения атрибута каждому list
в tables_list
.
tables_list <- lapply(tables$page, function(p) {
cat(p, "\n")
out <- extract_tables(Path,
pages = p,
encoding = "UTF-8",
method = "stream",
output = "matrix")
#This part of the code points out the title, page of each table and reporting year if applicable so we can keep track of what goes where
attr(out, "caption") <- paste(as.character(tables$page[tables$page %in% p]), tables$text[tables$page %in% p], tables$Reportingyear[tables$page %in% p], sep = " && ")
return(out)
})
Я не могу найти способ назначить эти атрибуты в качестве имен их соответствующих списков. У кого-нибудь есть идеи, как к этому подойти?