similar to: Multiple Vector with matrix in R

Displaying 20 results from an estimated 700 matches similar to: "Multiple Vector with matrix in R"

2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
Hello my friends, here is a code I wrote with no loops on matrix that is taking too long (2 seconds and I call him 720 times --> 12 minutes): mat1 and mat2 are both matrix with 103 columns and 164 rows. sequence <- matrix(seq(1 : ncol(mat1))) returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1) function<- function(mat1, mat2, colNb, day){
2007 Nov 12
1
update matrix with subset of it where only row names match
I guess this has a simple solution: I have matrix 'mat1' which has row and column names, e.g.: A B C row1 0 0 0 row2 0 0 0 .... rown 0 0 0 I have a another matrix 'mat2', essentially a subset of 'mat1' where the rownames are all in 'mat1' e.g.: B row3 5 row8 6 row54 7 I want to insert the values of matrix mat2 for column B (in reality it could be some or
2010 Jan 27
1
How to sort data.frame
Dear R heleprs   Suppose I have following data   Scenarios combination_names     series1    series2 Sc1 MAT2 GAU1 7.26554 8.409778 Sc2 MAT2 GAU2 7.438128 8.130275 Sc3 MAT3 GAU1 8.058422 8.06457 Sc4 MAT1 GAU2 8.179855 8.022071 Sc5 MAT3 GAU2 8.184033 8.191831 Sc6 MAT3 GAU2 7.50312 8.232425 Sc7 MAT1 GAU2 7.603291 8.200993 Sc8 MAT1 GAU1 8.221755 8.380097 Sc9 MAT3 GAU2 7.904908
2009 Apr 16
2
error bars in matplot
Hi, I was trying to get error bars in my matplot. I looked at an earlier thread, and the sample code that I made is: #------------------ library(plotrix) mat1 <- matrix(sample(1:30,10),nrow=5,ncol=2) ses <- matrix(sample(1:3,10,replace=T),nrow=5,ncol=2) vect <- seq(20,100,20) rownames(mat1) <- rownames(ses) <- vect colnames(mat1) <- colnames(ses) <- letters[1:2]
2005 Nov 03
4
merging dataframes
Dear List, I often have to merge two or more data frames containing unique row names but with some columns (names) common to the two data frames and some columns not common. This toy example will explain the kind of setup I am talking about: mat1 <- as.data.frame(matrix(rnorm(20), nrow = 5)) mat2 <- as.data.frame(matrix(rnorm(20), nrow = 4)) rownames(mat1) <- paste("site",
2013 Jan 31
1
lower corner cumulative probability
Dear useRs, With the following set of command i managed to create the copula density ================================================ >library(MASS) >library(evd) >X<-matrix(sample(1:3000), ncol=2) >U=cbind(rank(X[,1])/(nrow(X)+1),rank(X[,2])/(nrow(X)+1)) > mat1=kde2d(U[,1],U[,2],n=150) image(mat1$x,mat1$y,mat1$z,col= rev(heat.colors(1500)),xlab="",ylab="")
2013 Sep 26
1
Grouping Matrix by Columns; OHLC Data
HI, May be this helps: set.seed(24) ?mat1<- matrix(sample(1:60,30*24,replace=TRUE),ncol=24) colnames(mat1)<- rep(c("O","H","L","C"),6) indx<-seq_along(colnames(mat1)) n<- length(unique(colnames(mat1))) ?res<- lapply(split(indx,(indx-1)%%n+1),function(i) mat1[,i]) lapply(res,head,2) #$`1` #????? O? O? O? O? O? O #[1,] 18 56 51 24 24 52 #[2,]
2007 Jul 24
1
cor inside/outside a function has different output
I'm calculating correlations between two matrices mat1 <- matrix(sample(1:500,25), ncol = 5, dimnames=list(paste("mat1row", 1:5, sep=""), paste("mat1col", 1:5, sep=""))) mat2 <- matrix(sample(501:1000,25), ncol = 5, dimnames=list(paste("mat2row", 1:5, sep=""), paste("mat2col", 1:5, sep="")))
2003 Oct 31
2
Summing elements in a list
Hi, Suppose that I have a list where each component is a list of two matrices. I also have a vector of weights. How can I collapse my list of lists into a single list of two matrices where each matrix in the result is the weighted sum of the corresponding matrices. I could use a loop but this is a nested calculation so I was hoping there is a more efficient way to do this. To help clarify,
2010 Oct 14
1
rbind ing matrices and resetting column numbers
Sorry for the verbose example. I want to row bind two matrices, and all works except I want the column labelled "row" to be sequential in the new matrix, shown as "mat3" here, i.e. needs to be 1:6 and not 1:3 repeated twice. Any suggestions? Thanks J > colnm1 <- c("row","ti","counti") > colnm2 <-
2010 Jan 29
7
Simple question on replace a matrix row
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to replace the first row of mat2 with mat1, this is what I do: mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want it to stay a matrix... ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html Sent from the R help
2006 Aug 28
2
Cannot get simple data.frame binding.
I am stuck on a simple problem where an example works fine but the real one does not. I have a data.frame where I wish to sum up some values across the rows and create a new data.frame with some of old data.frame variables and the new summed variable. It works fine in my simple example but I am doing something wrong in the real world. In the real world I am loading a labeled data.frame. The
2013 Jan 10
1
merging command
HI Eliza, You could do this: set.seed(15) mat1<-matrix(sample(1:800,124*12,replace=TRUE),nrow=12) # smaller dataset #Your codes ?list1<-list() ?for(i in 1:ncol(mat1)){ ? list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x)) ? list1} ?x<-list1?? x<-matrix(unlist(x),nrow=12) x<-abs(x) ?y<-colSums(x, na.rm=FALSE) z<-matrix(y,ncol=10) ?z<-as.dist(z) ?z ?# ?? 1?? 2?? 3?? 4?? 5??
2007 Nov 21
2
matrix elementwise average with NA's
Hello fellow R users, I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example mat1 <- matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T) mat2 <- matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T) I'd like to compute the element-wise average for non-NA entries. Of course (mat1+mat2)/2
2010 Mar 29
2
Need help on matrix manipulation
Dear all, Ket say I have 3 matrices : mat1 <- matrix(rnorm(16), 4) mat2 <- matrix(rnorm(16), 4) mat3 <- matrix(rnorm(16), 4) Now I want to merge those three matrices to a single one with dimension 4*3=12 and 4 wherein on resulting matrix, row 1,4,7,10 will be row-1,2,3,4 of "mat1", row 2,5,8,11 will be row-1,2,3,4 of "mat2" and row 3,6,8,12 will be row-1,2,3,4 of
2007 Apr 20
2
R: Appending the files
Hello R-Experts, I am a beginner to R. Can someone please look at my problem I am trying to append the files in R but couldn't get the answer properly. My code is mat1<-matrix(0,2,3) mat2<-matrix(1,2,3) write.table(mat1,"foo.csv",sep=",",col.names=NA) write.table(mat2,"foo.csv", sep=",", col.names=NA, append = TRUE) I am getting a warning
2003 Mar 20
2
Matrix problems
Hi all. I do not know if it is a bug in the windows version but i have this problem. Reading a file with 200000 rows, 2 columns and transforming into a 200000 x 2 matrix. If I try to find an element by using the which command which gives some correct indexes plus some others passing the 200000 row boundaries. If I try to reach those "outbound" indexs I get an "Error: subscript out
2008 Aug 15
2
cor() btwn columns in two matrices - no complete element pairs
Hi everyone, I'm trying to calculate correlation coefficients between corresponding columns in two matrices with identical dimensions but different data. The problem is that the matrices contain NAs in different locations. I am using the following code to try to calculate correlations between complete sets of data: #Code start maxcol<-ncol(mat1) for (i in 1:maxcol) {
2011 May 10
2
need to delete by time, not date
I have a matrix where one column has a date and another column has a time. I need to delete all times before 6am. I had combined the Date and Time column into DateTime. Mat1: Weight Date Time 7.6 04/28/11 09:03 8.4 04/29/11 03:11 8.6 04/29/11 05:32 8.6 04/29/11 09:53 1.4 05/01/11 19:52 I tried just picking up the time: as.POSIXct(Mat1$Time, format = "%H:%M") but
2013 Mar 28
1
scatterplot3d with densCols ?
Hi, I was trying to make a 3D plot using densCols. The documentation for densCols doesn't look like it'll work for 3D. For example: ----------------------------------------- library(scatterplot3d) v1 <- rnorm(10000) v2 <- rnorm(10000) v3 <- rnorm(10000) ## 2D with denscols mat1 <- cbind(v1,v2) mcols1 <- densCols(mat1) plot(mat1,col=mcols1) mat <- cbind(v1,v2,v3)