Hello together, this is ma first post, so please aplogize me if post this in the wrong section. I have problem concerning ma two matrizes. After a regressione and so on, I got two matrizes Matrixres contains the results of ma calculation. Matrixr contains my detiene, which where Aldo used for the regression. Please ser the following code: #Datei einlesen residual = read.csv2("E:***Input-R_Renditen.csv",header=TRUE, sep=";") #Aktientitel alist <- list() for (a in 2:11){ #Regression ? ?#L?nge Gesamtzeit ? ?t <- 243 ? ?tx <- t-59 ? ?#L?nge Regression ? ?reglist <- list() ? ?for (i in 1:tx){ ? ?j <- i+59 ? ?#RegressionsVariable ? ?x = residual[i:j,a] ? ?rm = residual[i:j,12] ? ?smb = residual[i:j,13] ? ?hml = residual[i:j,14] ? ?rf = residual[i:j,15] ? ?#?berschussrenditen ? ?ex=x-rf ? ?erm=rm-rf ? ?#Regression ? ?reg <- lm(ex~erm+smb+hml) ? ?reglist[[i]] <- coef(reg) ? ? #Berechnung Residuum ? ?? ?#Residual Berechnung ? ?? ?rx = residual[(j-5):j,a] ? ?? ?rrm = residual[(j-5):j,12] ? ?? ?rsmb = residual[(j-5):j,13] ? ?? ?rhml = residual[(j-5):j,14] ? ?? ?rrf = residual[(j-5):j,15] ? ?? ?rex = rx-rrf ? ?? ?rerm = rrm-rrf ? ?? ?#Berechnung ? ?? ?res <- sum(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml))/sd(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml)) ? ?? ?reglist[[i]] <- res }? ? ? ? #Residuen auf alle Aktien ? ?alist[[a]] <- reglist } ? ? #Matrix mit Residuen ? ?matrixres <- do.call(cbind,alist) #Spaltennamen/Zeilennamen s<- names(residual)[2:11] colnames(matrixres)<-s #RenditeMatrix matrixr <- do.call(cbind,residual[60:243,2:11]) Now I want to combines the two matrizes in the following way: Under every row of matrixres should stand the row of matrixr for excample: Matrixres row1 Matrixr row1 Matrixres row2 Matrixr row 2 Can anybody help me? I was working on this problem the whole day, but have no idea. Thanks alot Thomash -- View this message in context: http://r.789695.n4.nabble.com/combining-two-different-matrizes-tp4668766.html Sent from the R help mailing list archive at Nabble.com.
On 05-06-2013, at 23:56, ThomasH <thomas.hufnagel1 at gmx.de> wrote:> > Hello together, > > this is ma first post, so please aplogize me if post this in the wrong > section. > > I have problem concerning ma two matrizes. > > After a regressione and so on, I got two matrizes > > Matrixres contains the results of ma calculation. > > Matrixr contains my detiene, which where Aldo used for the regression. > > Please ser the following code: > > #Datei einlesen > residual = read.csv2("E:***Input-R_Renditen.csv",header=TRUE, sep=";") > > > #Aktientitel > alist <- list() > for (a in 2:11){ > > > #Regression > #L?nge Gesamtzeit > t <- 243 > tx <- t-59 > > #L?nge Regression > reglist <- list() > for (i in 1:tx){ > j <- i+59 > > #RegressionsVariable > x = residual[i:j,a] > rm = residual[i:j,12] > smb = residual[i:j,13] > hml = residual[i:j,14] > rf = residual[i:j,15] > > #?berschussrenditen > ex=x-rf > erm=rm-rf > > #Regression > reg <- lm(ex~erm+smb+hml) > reglist[[i]] <- coef(reg) > > > #Berechnung Residuum > #Residual Berechnung > rx = residual[(j-5):j,a] > rrm = residual[(j-5):j,12] > rsmb = residual[(j-5):j,13] > rhml = residual[(j-5):j,14] > rrf = residual[(j-5):j,15] > > rex = rx-rrf > rerm = rrm-rrf > > #Berechnung > res <- > sum(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml))/sd(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml)) > reglist[[i]] <- res > } > > > #Residuen auf alle Aktien > alist[[a]] <- reglist > } > > #Matrix mit Residuen > matrixres <- do.call(cbind,alist) > > #Spaltennamen/Zeilennamen > s<- names(residual)[2:11] > colnames(matrixres)<-s > > #RenditeMatrix > matrixr <- do.call(cbind,residual[60:243,2:11]) > > > Now I want to combines the two matrizes in the following way: > > Under every row of matrixres should stand the row of matrixr for excample: > > Matrixres row1 > Matrixr row1 > Matrixres row2 > Matrixr row 2 > > Can anybody help me? I was working on this problem the whole day, but have > no idea.Something like this (assuming A and B have the same dimensions) set.seed(11) A <- matrix(round(rnorm(25),3),nrow=5) B <- matrix(1:25,nrow=5) C <- matrix(0,nrow=2*nrow(A),ncol=ncol(A)) crows <- seq.int(from=1,to=2*nrow(A),by=2) C[crows,] <- A C[crows+1,] <- B Some friendly advice: get someone to check your English before sending a mail to the list. Berend
You didn't give us data, but this may give you enough to solve your problem:> set.seed(42) > nrows <- 6 > ncols <- 5 > mat1 <- matrix(sample.int(100, 30), nrows, ncols) > mat1[,1] [,2] [,3] [,4] [,5] [1,] 92 70 83 39 7 [2,] 93 13 23 46 82 [3,] 29 61 40 73 98 [4,] 81 65 80 11 67 [5,] 62 42 88 78 33 [6,] 50 91 10 85 60> mat2 <- round(prop.table(mat1)*100, 2) > mat2[,1] [,2] [,3] [,4] [,5] [1,] 5.25 4.00 4.74 2.23 0.40 [2,] 5.31 0.74 1.31 2.63 4.68 [3,] 1.66 3.48 2.28 4.17 5.59 [4,] 4.62 3.71 4.57 0.63 3.82 [5,] 3.54 2.40 5.02 4.45 1.88 [6,] 2.85 5.19 0.57 4.85 3.42> newmat <- matrix(rbind(as.vector(mat1), as.vector(mat2)), nrows*2, ncols) > newmat[,1] [,2] [,3] [,4] [,5] [1,] 92.00 70.00 83.00 39.00 7.00 [2,] 5.25 4.00 4.74 2.23 0.40 [3,] 93.00 13.00 23.00 46.00 82.00 [4,] 5.31 0.74 1.31 2.63 4.68 [5,] 29.00 61.00 40.00 73.00 98.00 [6,] 1.66 3.48 2.28 4.17 5.59 [7,] 81.00 65.00 80.00 11.00 67.00 [8,] 4.62 3.71 4.57 0.63 3.82 [9,] 62.00 42.00 88.00 78.00 33.00 [10,] 3.54 2.40 5.02 4.45 1.88 [11,] 50.00 91.00 10.00 85.00 60.00 [12,] 2.85 5.19 0.57 4.85 3.42 ------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77840-4352 -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of ThomasH Sent: Wednesday, June 5, 2013 4:56 PM To: r-help at r-project.org Subject: [R] combining two different matrizes Hello together, this is ma first post, so please aplogize me if post this in the wrong section. I have problem concerning ma two matrizes. After a regressione and so on, I got two matrizes Matrixres contains the results of ma calculation. Matrixr contains my detiene, which where Aldo used for the regression. Please ser the following code: #Datei einlesen residual = read.csv2("E:***Input-R_Renditen.csv",header=TRUE, sep=";") #Aktientitel alist <- list() for (a in 2:11){ #Regression #L?nge Gesamtzeit t <- 243 tx <- t-59 #L?nge Regression reglist <- list() for (i in 1:tx){ j <- i+59 #RegressionsVariable x = residual[i:j,a] rm = residual[i:j,12] smb = residual[i:j,13] hml = residual[i:j,14] rf = residual[i:j,15] #?berschussrenditen ex=x-rf erm=rm-rf #Regression reg <- lm(ex~erm+smb+hml) reglist[[i]] <- coef(reg) #Berechnung Residuum #Residual Berechnung rx = residual[(j-5):j,a] rrm = residual[(j-5):j,12] rsmb = residual[(j-5):j,13] rhml = residual[(j-5):j,14] rrf = residual[(j-5):j,15] rex = rx-rrf rerm = rrm-rrf #Berechnung res <- sum(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml))/sd(rex-(reglist[[i]][2]*rerm+reglist[[i]][3]*rsmb+reglist[[i]][4]*rhml)) reglist[[i]] <- res } #Residuen auf alle Aktien alist[[a]] <- reglist } #Matrix mit Residuen matrixres <- do.call(cbind,alist) #Spaltennamen/Zeilennamen s<- names(residual)[2:11] colnames(matrixres)<-s #RenditeMatrix matrixr <- do.call(cbind,residual[60:243,2:11]) Now I want to combines the two matrizes in the following way: Under every row of matrixres should stand the row of matrixr for excample: Matrixres row1 Matrixr row1 Matrixres row2 Matrixr row 2 Can anybody help me? I was working on this problem the whole day, but have no idea. Thanks alot Thomash -- View this message in context: http://r.789695.n4.nabble.com/combining-two-different-matrizes-tp4668766.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Seemingly Similar Threads
- [rmetasim] Need help deciphering this error msg... targeted to those who use rmetasim...
- Error in as.environment(pos): using 'as.environment(NULL)' is defunct
- [LLVMdev] Instruction with variable number of outputs
- [LLVMdev] Instruction with variable number of outputs
- [LLVMdev] Instruction with variable number of outputs