Skip to content

date and matrices

1 message · arun

#
HI Elisa,

You also mentioned about more than 100 matrices with 1 column each.
Suppose, if the matrices are named from mat1:mat4 (In your case mat1:mat124)
mat1<-matrix(c(.314,.314,.273,.273,.236,.236,.236,.236,.273,.314,.403,.314),ncol=1) 
mat2<-matrix(c(.314,.325,.246,.273,.226,.236,.249,.236,.289,.314,.403,.314),ncol=1) 
mat3<-matrix(c(.314,.320,.275,.273,.236,.232,.236,.231,.273,.315,.413,.314),ncol=1) 
mat4<-matrix(c(.318,.327,.295,.273,.286,.236,.264,.236,.295,.315,.423,.314),ncol=1)

?res3<- lapply(paste0("mat",1:4),function(i) data.frame(date1,val=c(rep(get(i),182),head(get(i),8)),stringsAsFactors=FALSE))
????????????????????????????????????????? #change from 1:124

str(res3)
#List of 4
# $ :'data.frame':??? 2192 obs. of? 2 variables:
?# ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
?# ..$ val? : num [1:2192] 0.314 0.314 0.273 0.273 0.236 0.236 0.236 0.236 0.273 0.314 ...
?#$ :'data.frame':??? 2192 obs. of? 2 variables:
?# ..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
?# ..$ val? : num [1:2192] 0.314 0.325 0.246 0.273 0.226 0.236 0.249 0.236 0.289 0.314 ...
?#$ :'data.frame':??? 2192 obs. of? 2 variables:
? #..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
? #..$ val? : num [1:2192] 0.314 0.32 0.275 0.273 0.236 0.232 0.236 0.231 0.273 0.315 ...
?#$ :'data.frame':??? 2192 obs. of? 2 variables:
? #..$ date1: chr [1:2192] "1991.01.01" "1991.01.02" "1991.01.03" "1991.01.04" ...
?# ..$ val? : num [1:2192] 0.318 0.327 0.295 0.273 0.286 0.236 0.264 0.236 0.295 0.315 ...
?head(res3[[1]])
#?????? date1?? val
#1 1991.01.01 0.314
#2 1991.01.02 0.314
#3 1991.01.03 0.273
#4 1991.01.04 0.273
#5 1991.01.05 0.236
#6 1991.01.06 0.236


I am not sure whether you could do it in one step as memory might be an issue here.? You could split this to 2-3 times:
1:25, 24:50, and so on..
A.K.