我意外地构建了一个损坏的Dataframe。但是,我不知道为什么允许这样的构造,你有什么想法,这是一个bug吗?
在这里,你如何产生一个腐败的数据帧(查看“lv4”列 - “同意”而不是8的9个实例,就像lv1-lv8列中除lv4列之外的标签一样):
data_names<- structure(list(
vars = c("self esteem", "self image", "peers esteem", "family esteem", "public esteem", "knowledge esteem", "esteem on goods", "partner's esteem"),
lv1 = c("absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)", "absolutely disagree (5)"),
lv2 = c("disagree (4)", "disagree (4)", "disagree (4)", "disagree (4)", "disagree (4)", "disagree (4)", "disagree (4)", "disagree (4)"),
lv3 = c("neutral (3)", "neutral (3)", "neutral (3)", "neutral (3)", "neutral (3)", "neutral (3)", "neutral (3)", "neutral (3)"),
lv4 = c("agree (2)", "agree (2)", "agree (2)", "agree (2)", "agree (2)", "agree (2)", "agree (2)", "agree (2)", "agree (2)"),
lv5 = c("absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)", "absolutely agree (1)"),
lv6 = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_),
lv7 = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_),
lv8 = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_)),
.Names = c("vars", "lv1", "lv2", "lv3", "lv4", "lv5", "lv6", "lv7", "lv8"), row.names = c(NA, -8L), class = c("tbl_df", "tbl", "data.frame"))
以下是显示如下内容的错误消息:
t(data_names):
Error in as.matrix.data.frame(x) :
dims [product 72] do not match the length of object [73]
t(data_names["lv4"]):
Error in as.matrix.data.frame(x) :
dims [product 8] do not match the length of object [9]
table(data_names):
Error in table(data_names) : all arguments must have the same length
table(data_names["lv4"]):
agree (2)
9
table(data_names["lv3"]):
neutral (3)
8
while:
dim(data_names["lv4"]):
[1] 8 1
dim(data_names["lv3"]):
[1] 8 1
你能否提出为什么可以构造这些损坏的数据帧以及某些功能在操作时失败的原因?结构不负责提供一些错误信息?当table函数成功执行时,为什么dim函数无法报告“lv4”列的正确尺寸?