Displaying 20 results from an estimated 143 matches for "mat1".
Did you mean:
mat
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){
mat1<- matrix(mat1[, colNb] )
mat2<- matrix(mat...
2013 Sep 02
3
Product of certain rows in a matrix
Hi,
You could try:
A<- matrix(unlist(read.table(text="
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
",sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL)
library(matrixStats)
?res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds))
?res1
#? [,1] [,2] [,3]
#1??? 4?? 10?? 18
#2?? 63?? 64?? 63
#3?? 18?? 10??? 4
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", 1:5, sep="")
rownames(mat2) <- paste("site", 6:9, sep="")
names(mat1) <- paste("species", c(1,3,5,7), sep...
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 col...
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]
matplot(mat1,pch=c('x','o'),type = "b",lwd =...
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-questio...
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
8.088824
Sc10
MAT1 GAU3
7.67034
8.46376
I wish to sort thise data frame based on combination_names. Actually this is...
2005 Oct 06
1
Compare two distance matrices
Hi all,
I am trying to compare two distance matrices with R. I would like to
create a XY plot of these matrices and do some linear regression on
it. But, I am a bit new to R, so i have a few questions (I searched in
the documentation with no success).
The first problem is loading a distance matrix into R. This matrix is
the output of a the Phylip program Protdist and lookes like this:
5
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)
#$`...
2013 Sep 20
3
search species with all absence in a presence-absence matrix
Dear list
I have a matrix composed of islandID as rows and speciesID as columns.
IslandID: Island A, B, C….O (15 islands in total)
SpeciesID: D0001, D0002, D0003….D0100 (100 species in total)
The cell of the matrix describes presence (1) or absence (0) of the species
in an island.
Now I would like to search the species with absence (0)
in all the islands (Island A to Island O.)
2003 Oct 31
2
Summing elements in a list
...le 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, here is
the code I would use with a for loop
result <- list(mat1=matrix(0,nrow1,ncol1),
mat2=matrix(0,nrow2,ncol2))
for (i in seq(along=matlist)) {
result$mat1 <- result$mat1+w[i]*matlist[[i]]$mat1
result$mat2 <- result$mat2+w[i]*matlist[[i]]$mat2
}
I apologise if this is a trivial question. Unfortunately I don't have
my copy of...
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
does not work for the final two rows because of the NA's. Are there any elegant ways...
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="")
contour(mat1$x,mat1$y,mat1$z,add=
TRUE,levels = pretty(c(0,4), 11))
=========================================================
Is there a way we can find the cumulative probability...
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("mat...
2013 Apr 15
3
Indices of lowest values in matrix
Dear R users,Sorry for such a basic question. I really need to know that how can i pick the indices of 5 lowest values from each row of a matrix with dimensions 12*12??Thank you very much in advance
Elisa
[[alternative HTML version deleted]]
2012 Nov 16
4
Multiple Vector with matrix in R
Hi
Can someone show me an easy way to multiple a weighted vector with an
matrix?
example below
mat1<-matrix(sample(1:100,80,replace=TRUE),ncol=8)
w <- 1/1:10
I want the first element in w to be multiplied by the first row of mat1 and
2nd element in w to be multiplied with the 2nd row and so on.
I have huge matrix is there an easy way other than diag(w)%*%mat1
Thanks
--
View this messa...
2013 Sep 27
3
Compare species presence and absence between sites
Dear List,
I want to compare the presence and absence of bird species based on the
sites in a matrix.
The matrix has 5 rows for Island A, B, C, D, and E.
It has 100 columns for bird species D001-D100.
In each cell of the matrix,
the presence-absence of bird species will be recorded as 1 or 0.
(For example, if species D001 is found on Island D,
the matrix cell of species D001 and Island D
2003 Mar 20
2
Matrix problems
...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
of bounds" .
Is this a limitation of matrix function ? or am i doing something
wrong ?
Example :
> str(mat1)
num [1:200000, 1:2] 185 212 222 269 342 349 361 367 397 423 ...
> which(mat1 == 185)
[1] 1 201920 203792 205211 206604 220417 223767 225169 239420 243768 249351 249395 252077
What could be happening ?
Thanks in advance
Mark Marques
2010 Oct 14
1
rbind ing matrices and resetting column numbers
...quot; 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 <- c("row","tj","countj")
> mat1 <- matrix(c(1,7,9,2,8,5,3,7,9),byrow=T,nrow=3)
> colnames(mat1) <- colnm1
> mat1
row ti counti
[1,] 1 7 9
[2,] 2 8 5
[3,] 3 7 9
> mat2 <- matrix(c(1,5,3,2,6,8,3,3,7),byrow=T,nrow=3)
> colnames(mat2) <- colnm2
> mat2
row tj countj
[1,] 1...
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 this assigns the time value today's date.
The final matrix should lo...