search for: mymat

Displaying 20 results from an estimated 66 matches for "mymat".

Did you mean: mydat
2010 Jul 15
2
replace negative numbers by smallest positive value in matrix
Hi Group, I have a matrix, and I would like to replace numbers less than 0 by the smallest minimum number. Below is an small matrix, and the loop I used. I would like to get suggestions on the "R way" to do this. Thanks, Juliet # example data set mymat <- structure(c(-0.503183609420937, 0.179063475173256, 0.130473004669938, -1.80825226960127, -0.794910626384209, 1.03857280868547, 0.362120146065799, -2.01124119488992, -1.49083525457822, -0.356354715035589, -0.306686279071398, 0.0789120002882668, 1.50314029609087, -0.0177677865019544, 1.31642572...
2017 Jun 27
2
paste strings in C
Dear R-devs, Below is a small example of what I am trying to achieve, that is trivial in R and I would like to learn how to do in C, for very large matrices: > (mymat <- matrix(c(1,0,0,2,2,1), nrow = 2)) [,1] [,2] [,3] [1,] 1 0 2 [2,] 0 2 1 And I would like to produce: [1] "a*C" "B*c" Which can be trivially done in R via something like: foo <- function(mymat, colnms, tilde = FALSE) { apply(mymat, 1, functi...
2008 Sep 21
1
How to put given values in lower triangle of splom-plot?
...w. This works perfectly, but I would like to have a matrix of given correlation values to be used in the lower triangular part (lower.panel) of the splom-plot instead of calculated correlation values. Here is the matrix I would like to use (it can be any other convenient data structure): mymat=matrix(0,nrow=3,ncol=3) mymat[1,2]=0.2 mymat[1,3]=0.2 mymat[2,3]=0.5 If one can determine inside the lower.panel-function which columns of "data" are used for the current pairwise scatter plot, it should be easy to get the correct entries of "mymat", but how is this achieve...
2017 Jun 27
0
paste strings in C
To do this in C, it would probably be easier and faster to just do the string manipulation directly. Luckily, there are already packages that have done this for you. See an example below using the S4Vectors package. foo2 <- function(mymat, colnms, tilde=FALSE) { chars <- colnms[col(mymat)] lowerChars <- if (tilde) paste0("~", chars) else tolower(chars) chars <- ifelse(mymat==1L, lowerChars, chars) keep <- mymat > 0L charList <- split(chars[keep], row(chars)[keep]) S4Vectors::unstrs...
2011 Oct 01
1
class definition
Hi everybody! I have a matrix of class "myClass", for example: myMat <- matrix(rnorm(30), nrow = 6) attr(myMat, "class") <- "myClass" class(myMat) When I extract part of ''myMat'', the corresponding class ''myClass'' unfortunately disappear: myMat.p <- myMat[,1:2] class(myMat.p) Please for any advice /...
2006 Mar 21
1
rownames, colnames, and date and time
...lass POSIXlt in all cases (dataframes and matrices, rownames, colnames, names) produces an error. Demonstration code is given below. This is somewhat inconsistent. Perhaps a reasonable solution could be that the typecast used for POSIXct and dataframes is used in all the other cases also. Code: mymat<-matrix(1:4,nrow=2,ncol=2) mydf<-data.frame(mymat) mydates<-as.POSIXct(c("2001-1-24","2005-12-25")) rownames(mydf)<-mydates names(mydf)<-mydates rownames(mymat)<-mydates colnames(mymat)<-mydates print(deparse(mydates)) print(deparse(rownames(mydf))) print(...
2006 Mar 21
1
rownames, colnames, and date and time
...lass POSIXlt in all cases (dataframes and matrices, rownames, colnames, names) produces an error. Demonstration code is given below. This is somewhat inconsistent. Perhaps a reasonable solution could be that the typecast used for POSIXct and dataframes is used in all the other cases also. Code: mymat<-matrix(1:4,nrow=2,ncol=2) mydf<-data.frame(mymat) mydates<-as.POSIXct(c("2001-1-24","2005-12-25")) rownames(mydf)<-mydates names(mydf)<-mydates rownames(mymat)<-mydates colnames(mymat)<-mydates print(deparse(mydates)) print(deparse(rownames(mydf))) print(...
2007 Mar 12
1
How to avoid a for-loop?
Hi all, as I am trying to move slowly from just "working" to "good" code, I'd like to ask if there's a smarter way than using a for-loop in tasks like the example below. I need to obtain the extrema of the cumulated sum of a detrended time series. The following code is currently used, please have a look at the comments for my questions and remarks: system.time({ X
2006 Jul 03
1
rownames, colnames, and date and time
...matrices, rownames, colnames, names) produces an error. > >Demonstration code is given below. > >This is somewhat inconsistent. >Perhaps a reasonable solution could be that the typecast used >for POSIXct and dataframes is used in all the other cases also. > >Code: > >mymat<-matrix(1:4,nrow=2,ncol=2) >mydf<-data.frame(mymat) >mydates<-as.POSIXct(c("2001-1-24","2005-12-25")) > >rownames(mydf)<-mydates >names(mydf)<-mydates >rownames(mymat)<-mydates >colnames(mymat)<-mydates > >print(deparse(mydates)) &...
2009 Aug 26
3
changing equal values on matrix by same random number
Dear all, I have about 30,000 matrix (512x512), with values from 1 to N. Each value on a matrix represent a habitat patch on my matrix (i.e. my landscape). Non-habitat are stored as ZERO. No I need to change each 1-to-N values for the same random number. Just supose my matrix is: mymat<-matrix(c(1,1,1,0,0,0,0,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 0,0,0,0,2,2,2,0,0,0,0, 3,3,0,0,0,0,0,0,0,4,4, 3,3,0,0,0,0,0,0,0,0,0), nrow=5) I would like that all cells with 1 come to be runif(1,min=0.4, max=0.7), and cells with 2 be replace by another runif(...). I can do it using for(), but it is v...
2011 Aug 25
2
How to store the output of a loop into a matrix??
Hello, I want to create a matrix of N random numbers with a uniform distributions. Later, I want to repeat T times each row of this matrix. For this I do the following loop: N<-45 T<-10 n<-N*T a<-matrix(runif(N,min=-1,max=1),nr=N) mymat<-matrix(rep(NA,n),nr=n,nc=1) for(i in i:N){ b<-rep(a[i,],T) mymat[i,]<-b } Mi problem is that with this loop I can see the output of the loop but I canot get the matrix (mymat) that contains the full output of the loop. Please, somebody know how can I create a matrix that contains the ou...
2010 Mar 23
2
Adding matrix rows that have the same name?
..."A","B","C","A","C","C","D","E","F") name<- c("jim", "jim", "jim", "bob", "bob", "harry", "harry", "harry", "harry") MyMat <- cbind (a, b) rownames (MyMat) <- name dum.mat.temp <- dummy ("b", MyMat) #dum.mat.temp <-cbind (name, dum.mat.temp) # if you want names as a column dum.mat.temp Many thanks in advance! --Sarah
2005 Oct 11
1
problems with levelplot and contourplot
Hello, Using the following code i want to make a level or contourplot of some data that I produced library(grid);library(lattice); mydata <- read.table("avgee.dat"); mymat <- as.matrix(mydata); mymat <-t(mymat) vals<-as.vector(mymat); conc<-c(0.0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5); a<- c(0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5,5.0, 7.5,10, 25, 50, 75, 100); grid<-expand.grid(x=conc, y=a); levelplot(vals ~ conc * a, grid, regio...
2005 Apr 15
4
function corresponding to map of perl
Is there a function in R that corresponds to the function ``map'' of perl? It could be called like: vector.a <- map( vector.b, FUN, args.for.FUN ) It should execute for each element ele.b of vector.b: FUN( vector.b, args.for.FUN) It should return a vector (or data.frame) of the results of the calls of FUN. It nearly works using: apply( data.frame( vector.b ), 1, FUN,
2009 Jul 13
1
Add grand mean to every entry in a matrix
Hi, I have a matrix: mymat <- matrix(runif(10*4), ncol=4) I wish to subtract the column means, down the colums, subtract the row means from the rows and add back the grand mean - all the means should be the means of mymat rather than of the new matrix. How can I do this? Any help much appreciated. Thanks Tom ______...
2010 Jan 15
1
Lattice: How to color the data points in splom() according to the panel they are plotted?
...ter plot matrix are shown in the specified color? Cheers, Marius Here is the code: library(lattice) entrymat=matrix(0,nrow=3,ncol=3) entrymat[1,2]="black" entrymat[1,3]="blue" entrymat[2,3]="red" entrymat=t(entrymat) splom(~iris[,1:3],superpanel=function(z,...){ mymat.df=data.frame(rows=as.vector(row(entrymat)),cols=as.vector(col(entrymat)),entries=as.vector(entrymat)) mymat.df=subset(mymat.df,cols<rows) with(mymat.df,{ panel.text(x=rows,y=cols,labels=entries) }) panel.pairs(z,upper.panel=panel.splom,lower.panel=function(...){},...) },varnames=c(&q...
2010 Jun 10
3
Retrieving the 2 row of "dist" computations
...than the numerical value of the distance itself. For example, If the minimum distance in the following sample run is d[14], which is .3826119, and the rows are 4 & 6. I need to find a generic way to retrieve these rows, for a generic matrix of NRows (in this example NRows=7) NCols=5 NRows=7 myMat<-matrix(runif(NCols*NRows), ncol=NCols) d<-dist(myMat) 1 2 3 4 5 6 2 0.7202138 3 0.7866527 0.9052319 4 0.6105235 1.0754259 0.8897555...
2011 Feb 21
1
Query: matrix definition
Dear list users, if within a function I first define a matrix mymat <- matrix(NA, nrow=m, ncol=n) and somewhere afterwards by mistake mymat <- c(1,2,3) this second command deletes the first one. How can I make sure that within the function mymat will always remain the matrix defined at the beginning, without possibility of changing it throughout the code? Sec...
2009 Dec 04
2
how to seperate a matrix
Hello, I am working on seperate the matrix to two matrices but got trouble on doing it. Please give me some suggestions on doing this. Thanks a looooooooooooot! My original matrix m is as follows for example, [,1] [,2] [,3] [1,] 6 8 1 [2,] 5 9 2 [3,] 20 10 3 [4,] 7 11 4 [5,] 8 12 5 [6,] 25 13 6 [7,] 14 14 7 I want to generate two
2008 Jan 26
2
scatterplot3d with categorical data
Dear users, I'm trying to produce a 3d bar plot but the x and y dimensions have categorical data -- so I only want 3 points on each axis. So I try: require(scatterplot3d) mymat<-data.frame( x=c(1,1,1,2,2,2,3,3,3), y=c(1,2,3,1,2,3,1,2,3), z=c(1,2,3,4,5,6,7,8,9)) scatterplot3d(mymat, type="h", lwd=5, pch=" ", xlab="xlabel", ylab="ylabel", zlab="zlabel", xlim=c(1,3), ylim=c(1,3), lab=c(3,3), x.ti...