R:如何解决'dimnames'长度[1]不等于数组范围和数据长度[92]不是行数[24]的子倍数或倍数?



我正在尝试创建一个矩阵,但它显示以下错误:

有什么建议吗?Datos对象长度为92

datos<-c(Mondays,Tuesdays,Wednesdays,Thursdays)
dias<-c("Monday","Tuesday","Wednesday","Thursday")
horas<-0:23
days<-matrix(datos, nrow=24,ncol=4,dimnames=list(dias, horas))
days
length of 'dimnames' [1] not equal to array extent
In addition: Warning message:
In matrix(datos, nrow = 24, ncol = 4, dimnames = list(dias, horas)) :
data length [92] is not a sub-multiple or multiple of the number of rows [24]

我试图创建一个矩阵,但它显示了这些错误。如何理解这个问题以解决它

如果"datos"的长度为92,我们可以在末尾附加NAs,使其为24的倍数,即96

matrix(`length<-`(datos, 24 *4), nrow=24, ncol = 4, dimnames = list(horas, dias))

最新更新