我有一个大约3000行乘7000列的data.frame。列包含随时间收集的值。第一列包含指示测量开始的实时的实时值。举例说明:
mat1 <- c(00.00,"f","g","f","g")
mat2 <- c(00.50,"f","g","f","g")
mat3 <- c(00.25,"f","g","f","g")
mat <- as.data.frame(rbind(mat1, mat2, mat3))
colnames(mat) <- c("realtime","datatime1","datatime2","datatime3","datatime4")
mat
我想在数据中找到季节性,然后将其删除。为此,我需要将收集的数据以相同的实时时间放在同一列中,并用零或其他任何内容填充开头和结尾。为了说明,我需要这样的东西:
mat1 <- c(00.00,"f","g","f","g",0,0)
mat2 <- c(0,0,00.50,"f","g","f","g")
mat3 <- c(0,00.50,"f","g","f","g",0)
mat <- as.data.frame(rbind(mat1, mat2, mat3))
colnames(mat) <- c("realtime","datatime1","datatime2","datatime3","datatime4")
mat
到目前为止,我一直尝试了几件事,但他们最终都需要手动更改我提取的每一行或数据子集。 一个例子是:
mat1 <- c(rep(0,as.numeric(mat[1,1])*4),mat[1,],rep(0,96-(as.numeric(mat[1,1]))*4))
mat2 <- c(rep(0,as.numeric(mat[2,1])*4),mat[2,],rep(0,96-(as.numeric(mat[2,1]))*4))
mat3 <- c(rep(0,as.numeric(mat[3,1])*4),mat[3,],rep(0,96-(as.numeric(mat[3,1]))*4))
rbind(mat1,mat2,mat3)
如果没有所有这些手动修改,有没有人知道如何做到这一点?