我的数据框如下:
##DUMMY DATAFRAME
text = c("This is neutral")
Col2 = 0
Col3 = 0
Col4 = 0
Col5 = 0
Col6 = 0
Col7 = 0
Col8 = 0
Col9 = 0
Col10 = 0
Col11 = 0
Col12 = 0
Col13 = 0
Col14 = 0
Col15 = 0
Col16 = 0
df = data.frame(text, Col2, Col3, Col4, Col5, Col6, Col7, Col8, Col9, Col10, Col11, Col12, Col13, Col14, Col15, Col16)
df
text Col2 Col3 Col4 Col5 Col6 Col7 Col8 Col9 Col10 Col11 Col12 Col13 Col14 Col15 Col16
1 This is neutral 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
我想检查列表的长度,如果长度= 0,则返回上面的数据帧,如果不返回不同的数据帧。会发生的是它只需要第一个元素,而不是整个数据帧。
new_df <- ifelse(length(example_of_empty_list) == 0, df, different_df)
此输出只会给我
[[1]]
[1] This is neutral
Levels: This is neutral
我希望我的输出更像是整个数据帧而不是第一个元素。
我将如何做到这一点?