【发布时间】:2019-05-30 12:31:07
【问题描述】:
我有一个列表(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"
这是我为tables_list 中的每个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)
})
我想不出一种方法将这些属性分配为它们各自列表的名称。有没有人知道如何解决这个问题?
【问题讨论】:
标签: r list attributes names