2
我有一个数据帧,并检查数据帧的所有列是否包含数字值。数据帧的所有列中的测试条件
V1 V2 V3
1 114 9.078186 1.6310523
2 116 8.228931 1.6405415
3 117 8.043536 1.6625413
4 118 6.179346 0.8489116
我用
sapply(df,is.numeric)
这将返回
V1 V2 V3
TRUE TRUE TRUE
现在我该如何检查是否所有列是数字的?我在寻找类似:
if(sapply(df,is.numeric)==TRUE)
print(" All are Numeric")
但只检查一个条件,如向量的长度超过一个,因此通过警告
Warning message:
In if (sapply(df, is.numeric) == TRUE):
the condition has length > 1 and only the first element will be used