我对 R 中的 data.frame 结构可能有一个非常基本的问题。我将a *.dta
文件中的以下数据放入带有read.dta (library(foreign))
.
dput(head(barriers))
structure(list(risk = structure(c(1L, 1L, 1L, 1L, 1L, NA), .Label = c("Important",
"Somewhat important", "Somewhat unimportant", "Unimportant"), class = "factor"),
cap = structure(c(1L, 1L, 1L, 1L, 1L, NA), .Label = c("Important",
"Somewhat important", "Somewhat unimportant", "Unimportant"
), class = "factor"), FS_qual = structure(c(1L, 1L, 1L, 1L,
1L, NA), .Label = c("Important", "Somewhat important", "Somewhat unimportant",
"Unimportant"), class = "factor"), best_prac = structure(c(1L,
1L, 1L, 1L, 2L, NA), .Label = c("Important", "Somewhat important",
"Somewhat unimportant", "Unimportant"), class = "factor"),
const_risk = structure(c(1L, 2L, 1L, 1L, 1L, NA), .Label = c("Important",
"Somewhat important", "Somewhat unimportant", "Unimportant"
), class = "factor"), appr = structure(c(3L, 2L, 2L, 1L,
1L, NA), .Label = c("Important", "Somewhat important", "Somewhat unimportant",
"Unimportant"), class = "factor"), instr = structure(c(1L,
1L, 2L, 1L, 3L, NA), .Label = c("Important", "Somewhat important",
"Somewhat unimportant", "Unimportant"), class = "factor"),
refin = structure(c(1L, 1L, 2L, 1L, 1L, NA), .Label = c("Important",
"Somewhat important", "Somewhat unimportant", "Unimportant"
), class = "factor"), reg = structure(c(1L, 1L, 2L, 1L, 2L,
NA), .Label = c("Important", "Somewhat important", "Somewhat unimportant",
"Unimportant"), class = "factor"), prop_qual = structure(c(1L,
2L, 2L, 1L, 1L, NA), .Label = c("Important", "Somewhat important",
"Somewhat unimportant", "Unimportant"), class = "factor")), datalabel = "", time.stamp = "13 Apr 2015 19:26", formats = c("%8.0g",
"%8.0g", "%8.0g", "%30.0g", "%10.0g", "%10.0g", "%106s", "%10.0g",
"%45s", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g",
"%36s", "%8.0g", "%8.0g", "%10.0g", "%20.0g", "%20.0g", "%20.0g",
"%20.0g", "%20.0g", "%20.0g", "%87s", "%14.0g", "%10.0g", "%10.0g",
"%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%10.0g", "%8.0g",
"%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%10.0g",
"%10.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%8.0g", "%10.0g",
"%20.0g", "%20.0g", "%20.0g", "%20.0g", "%20.0g", "%20.0g", "%20.0g",
"%20.0g", "%20.0g", "%20.0g", "%20.0g", "%82s", "%17.0g", "%17.0g",
"%17.0g", "%17.0g", "%17.0g", "%17.0g", "%17.0g", "%17.0g", "%70s",
"%21.0g"), types = c(253L, 251L, 251L, 251L, 255L, 255L, 106L,
255L, 45L, 251L, 251L, 251L, 251L, 251L, 251L, 36L, 251L, 251L,
255L, 255L, 255L, 255L, 255L, 255L, 255L, 87L, 255L, 255L, 255L,
251L, 251L, 251L, 251L, 251L, 255L, 251L, 251L, 251L, 251L, 251L,
251L, 251L, 255L, 255L, 251L, 251L, 251L, 251L, 251L, 255L, 255L,
255L, 255L, 255L, 255L, 255L, 255L, 255L, 255L, 255L, 255L, 82L,
255L, 255L, 255L, 255L, 255L, 255L, 255L, 255L, 70L, 251L), val.labels = c("",
"", "", "ownership", "Q36", "q37", "", "q38", "", "q39", "q39",
"q39", "q39", "q39", "q39", "", "q39", "q39", "", "q310", "q310",
"q310", "q310", "q310", "q310", "", "q411", "", "", "q413", "q413",
"q413", "q413", "q413", "", "q413", "q413", "q413", "q413", "q413",
"q413", "q413", "q414", "", "q413", "q413", "q413", "q413", "q413",
"", "q310", "q310", "q310", "q310", "q310", "q310", "q310", "q310",
"q310", "q310", "q310", "", "q417", "q417", "q417", "q417", "q417",
"q417", "q417", "q417", "", "type"), var.labels = c("Bank ID",
"BUKU: Type of Bank’s Activity based on Capital", "Bank ID",
"Ownership", "Q36_Do you consider sustainable finance as a profitable business area? ",
"Q37_Does your institution’s 2015 business plan contain financing for sustainable",
"Q37_Year planned", "Q38_Does your company have special unit that handles sustainable finance?",
"Q38_Sustainable Finance Unit", "Q39_A Dummy: Ever financed any sector?",
"Q39_A Have you ever provided financing to support eco-tourism",
"Q39_A Have you ever provided financing to support energy efficiency",
"Q39_A Have you ever provided financing to support power production (• Powe",
"Q39_A Have you ever provided financing to support organic agriculture?",
"Q39_A Have you ever provided financing to support waste treatment?",
"Q39_Name of other supported sustainable sectors", "Q39_A Have you ever provided financing to support recycled crafts/products?",
"Q39_A Have you ever provided financing to support waste treatment?",
"Q39_Total financing volume to support sustainable projects in 2014",
"Q310a Barrier for your institution to extend loan on sustainable finance: too ri",
"Q310b Barrier for your institution to extend loan on sustainable finance: Not pr",
"Q310c Barrier for your institution to extend loan on sustainable finance: Too co",
"Q310d Barrier for your institution to extend loan on sustainable finance: Lack o",
"Q310e Barrier for your institution to extend loan on sustainable finance: Instit",
"Q310f Barrier for your institution to extend loan on sustainable finance: others",
"Q310f Other barrier name", "Q411 In the past 5 years, has your institution received a request for financing ",
"Q412 In the past 5 years, has your institution financed an RE project as part of",
"Q413a Number of RE projects financed", "Q413b Dummy: Has financed biomass projects?",
"Q413b Dummy: Has financed geothermal projects?", "Q413b Dummy: Has financed hydro projects?",
"Q413b Dummy: Has financed solar projects?", "Q413b Dummy: Has financed wind projects?",
"Q413c Total RE financing", "Q413d Dummy: Has financed using Equity Finance?",
"Q413d Dummy: Has financed using Debt Finance (long term: more than 4 years)?",
"Q413d Dummy: Has financed using Debt Finance (medium term: 1 to 4 years)?",
"Q413d Dummy: Has financed using Mezzanine Finance ?", "Q413d Dummy: Has financed using Other",
"Q413d Dummy: Has financed using Project Finance", "Q413d Dummy: Has financed using Debt Finance (short term: less than 1 year)?",
"Q414 In the past 5 years, has your institution financed an RE project as part of",
"Q415a Number of RE CSR projects", "Q413b Dummy: Has financed biomass projects with CSR?",
"Q413b Dummy: Has financed geothermal projects with CSR?", "Q413b Dummy: Has financed hydro projects with CSR?",
"Q413b Dummy: Has financed solar projects with CSR?", "Q413b Dummy: Has financed wind projects with CSR?",
"Q415c Total CSR RE Investment", "Q416 Barrier for RE Investment: High default risk",
"Q416 Barrier for RE Investment: Lack of in-house capacities",
"Q416 Barrier for RE Investment: Low quality of feasibility studies",
"Q416 Barrier for RE Investment: Lack of best-practice RE financing examples",
"Q416 Barrier for RE Investment: High risk of construction delays ",
"Q416 Barrier for RE Investment: High costs of project appraisal",
"Q416 Barrier for RE Investment: Lack of adequate financial instruments ",
"Q416 Barrier for RE Investment: Lack of long-term refinancing opportunities",
"Q416 Barrier for RE Investment: Restrictive banking regulation ",
"Q416 Barrier for RE Investment: Low quality of project proposals",
"Q416 Barrier for RE Investment: Others", "Q416 Barrier for RE Investment: Name of other barrier",
"Q417 Support Initiatives: In-house training and manuals", "Q417 Support Initiatives: Access to external technical expertise",
"Q417 Support Initiatives: Guarantee instruments", "Q417 Support Initiatives: Long-term refinancing sources",
"Q417 Support Initiatives: Public co-financing opportunities",
"Q417 Support Initiatives: Portfolio requirements by OJK", "Q417 Support Initiatives: Disclosure requirements by OJK",
"Q417 Support Initiatives: Others", "Q417 Support Initiatives: Name of other initiatives",
"Type of Financial Institution"), version = 12L, label.table = structure(list(
Q36 = structure(1:3, .Names = c("Yes", "No", "Don't know"
)), q37 = structure(1:3, .Names = c("Yes", "No", "Not Yet"
)), q38 = structure(1:2, .Names = c("Yes", "No")), q39 = structure(0:1, .Names = c("No",
"Yes")), q310 = structure(1:4, .Names = c("Important", "Somewhat important",
"Somewhat unimportant", "Unimportant")), q411 = structure(1:4, .Names = c("Yes",
"Not yet", "Don't know", "Not applicable")), q413 = structure(0:1, .Names = c("No",
"Yes")), q414 = structure(1:3, .Names = c("Yes", "Not yet",
"Don't know")), q417 = structure(1:4, .Names = c("Very useful",
"Somewhat useful", "Not very useful", "Not at all useful"
)), ownership = structure(1:4, .Names = c("BUMN State-owned enterprise",
"BUMD Regional-owned enterprise", "Foreign private ownership",
"Domestic private ownership")), type = structure(c(10L, 20L,
40L), .Names = c("Bank", "Pension Fund", "Financing Institution"
))), .Names = c("Q36", "q37", "q38", "q39", "q310", "q411",
"q413", "q414", "q417", "ownership", "type")), .Names = c("risk",
"cap", "FS_qual", "best_prac", "const_risk", "appr", "instr",
"refin", "reg", "prop_qual"), row.names = c("1", "2", "3", "4",
"5", "6"), class = "data.frame")
现在我想使用likert()
函数likert library
来组装发散堆积条形图并得到以下错误消息:
lik <- likert(mybs)
Error in dimnames(x)[[2]] <- levels :
length of 'dimnames' [2] not equal to array extent
我不太确定这意味着什么。有人可以指出我解决此错误消息吗?
编辑:
好的,问题似乎是冲突包之一:我加载了 HH 库和 likert 库,这似乎导致库(likert)出现问题。
R version 3.1.3 (2015-03-09)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] HH_3.1-15 gridExtra_0.9.1 multcomp_1.4-0 TH.data_1.0-6 survival_2.38-1
[6] mvtnorm_1.0-2 latticeExtra_0.6-26 RColorBrewer_1.1-2 lattice_0.20-31 likert_1.2
[11] xtable_1.7-4 ggplot2_1.0.1 dplyr_0.4.1 plyr_1.8.1 foreign_0.8-63
[16] lubridate_1.3.3
loaded via a namespace (and not attached):
[1] abind_1.4-3 acepack_1.3-3.3 assertthat_0.1 bitops_1.0-6 car_2.0-25 class_7.3-12
[7] cluster_2.0.1 codetools_0.2-11 colorspace_1.2-6 DBI_0.3.1 digest_0.6.8 e1071_1.6-4
[13] Formula_1.2-1 gtable_0.1.2 Hmisc_3.15-0 htmltools_0.2.6 httpuv_1.3.2 httr_0.6.1
[19] lazyeval_0.1.10 leaps_2.9 lme4_1.1-7 magrittr_1.5 MASS_7.3-40 Matrix_1.2-0
[25] memoise_0.2.1 mgcv_1.8-6 mime_0.3 minqa_1.2.4 mnormt_1.5-2 munsell_0.4.2
[31] nlme_3.1-120 nloptr_1.0.4 nnet_7.3-9 parallel_3.1.3 pbkrtest_0.4-2 proto_0.3-10
[37] psych_1.5.1 quantreg_5.11 R6_2.0.1 Rcmdr_2.1-7 RcmdrMisc_1.0-2 Rcpp_0.11.5
[43] RCurl_1.95-4.5 reshape_0.8.5 reshape2_1.4.1 RJSONIO_1.3-0 rpart_4.1-9 sandwich_2.3-3
[49] scales_0.2.4 shiny_0.11.1 SparseM_1.6 splines_3.1.3 stringr_0.6.2 swirl_2.2.21
[55] tcltk_3.1.3 tcltk2_1.2-11 testthat_0.9.1 tools_3.1.3 vcd_1.3-2 yaml_2.1.13
[61] zoo_1.7-12
所以问题似乎likert()
在于库(HH)中的函数,而不是库(likert)。有人遇到过类似的麻烦吗?