search for: mat

Displaying 20 results from an estimated 2352 matches for "mat".

Did you mean: at
2004 Dec 10
1
subset bug?
...tree positions, sizes, and types (containing the columns TRT, COMP, PLOT, X, Y, DBH and CON) and wanted to make a stem map of the plot using different symbols and colors to represent the different types of tree stems. I copied a bit of the code below, the part that gave me troubles: if(dim(subset(mat,CON==1 & DBH>11.43))[1]>0) symbols(mat[mat$CON==1 & mat$DBH>11.43,]$X,mat[mat$CON==1 & mat$DBH>11.43,]$Y,circles=log(mat[mat$CON==1 & mat$DBH>11.43,]$DBH)*tuner,inches=FALSE,add=TRUE,fg="gray",lwd=2) if(dim(subset(mat,CON==0 & DBH>11.43))[1]>0...
2023 Jan 27
3
implicit loop for nested list
> > I am looking for a more elegant way to write below code. > > #Simulation results have different dimensions > mysim <- lapply(1:10, function(y) { > two.mat <- matrix(rnorm(4), nrow = 2) > four.mat <- matrix(rnorm(16), nrow = 4) > list(two.mat = two.mat, four.mat = four.mat) #results with different dimensions > }) > > #Collect different components of simulation results > #Is it possible to do this with implicit loops? &gt...
2023 Jan 27
1
implicit loop for nested list
I would use replicate() to do an operation with random numbers repeatedly: ``` mysim <- replicate(10, { two.mat <- matrix(rnorm(4), 2, 2) four.mat <- matrix(rnorm(16), 4, 4) list(two.mat = two.mat, four.mat = four.mat) }) ``` which should give you a matrix-list. You can slice this matrix-list just like normal, then cbind it in one step: ``` two.mat <- do.call("cbind", mysim[&quot...
2017 Jan 19
2
Error en loop anidado con data.table
...a, simplificada en número de niveles por variable, para crear un ejemplo más sencillo: id anio t_8a t_10a t_12a rankf8 rankf10 rankf12 1 1 100 220 220 NA NA NA 2 1 140 350 350 NA NA NA 3 2 55 165 165 NA NA NA 4 2 60 200 200 NA NA NA 5 2 100 NA NA NA NA NA 6 3 NA 350 350 NA NA NA También tengo una matriz, "mat" con la siguiente estructura: t_8a t_10a t_12a 1 100 200 200 2 50 150 150 3 NA 250 250 La columna rankf8 la quiero rellenar tomando como referencia valores de t_8a en "datos" en relación al valor de t_8a en la matriz "mat" y según el año...
2011 Aug 21
1
Multiple R linear models into one Latex table
...s(coef(modelos[[i]]))) var.names[c(k:c(k+l-1))]<-names(coef(modelos[[i]])) k<-k+l } var.names<-unique(var.names) if(is.null(final.varnames)) { final.varnames<-var.names } if(is.null(model.names)) { model.names<-paste("Model",1:length(modelos)) } mat.all<-matrix(data=NA, nrow=length(var.names)*2, byrow=FALSE, ncol=length(model.names), dimnames=list(c(rep(c("coef","sd"),length=length(var.names)*2)), c(model.names))) dimnames(mat.all)[[1]][c(seq(1,dim(mat.all)[1], by=2))]<-var.names; dimnames(mat.all)[[1]][c(seq(2,dim(...
2005 Aug 03
2
using weighted.mean with tapply()
I am trying to calculate the weighted mean for a of 10 deciles and I get an error: > decile <- tapply(X=mat$trt1m, INDEX=mat$Rank, FUN=weighted.mean, w=mat$mcap) Error in FUN(X[[1]], ...) : 'x' and 'w' must have the same length All three of my inputs have the same length, as shown below, and the weighted.mean calculation works by itself, just not in tapply() > length(mat$Rank) [1] 18...
2010 Aug 03
4
Need help on upper.tri()
HI, I am really messing up to make a symmetrical matrix using upper.tri() & lower.tri() function. Here is my code:   > set.seed(1) > mat = matrix(rnorm(25), 5, 5) > mat            [,1]       [,2]       [,3]        [,4]        [,5] [1,] -0.6264538 -0.8204684  1.5117812 -0.04493361  0.91897737 [2,]  0.1836433  0.4874291  0.3898432 -0.01619...
2007 Oct 24
1
Error in nls model.frame
Error in model.frame When I run the following nls model an error message appears and I dont know how to solve that. Could you help me?? mat = c(1,2,3,4,5,6,7,8,9,12,16,24,36,48,60) for (i in 1:length(j30)) { bliss = nls(c(j[i,1:length(mat)]) ~ b0 + b1*((1-exp(-k1*mat))/(k1*mat)) + b2*(((1-exp(-k2*mat))/(k2*mat))-exp(-k2*mat)), start = list(k1=0.1993, k2=0.1993, b0= 22.0046, b1=-2.7661, b2=-5.8912), trace = TRUE) }...
2009 Jul 15
1
Matrix multiplication precision
Hi!! I am trying to multiply 5 matrices and then using the inverse of that matrix for further computation. I read about precision problems from the archives and the suggestion was to use as.numeric while computing the products. I am still having problems with the results. Here is how I am using it #Mn.mat<-(T.mat %*% Rz.mat %*%...
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all, I have a problem with the "subset()" function. I spent all day yesterday with a collegue to solve it and we did not find a satisfying solution (even in the archived mails), so I ask for your help. Let's say (for a simple example) a matrix mat: R> mat cola colb colc [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 My goal is to select the lines of the matrix on the basis of the values of more than one column (let's say colb and colc). For example I want to select all the lines of the matrix for which values in colb and colc are more...
2008 Aug 13
2
missing TRUE/FALSE error in conditional construct
Hi everyone, I posted something similar to this in reply to another post, but there seems to be a problem getting it onto the board, so I'm starting a new post. I am trying to use conditional formatting to select non-zero and non-NaN values from a matrix and pass them into another matrix. The problem is that I keep encountering an error message indicating the ":missing value where TRUE/FALSE needed " My code is as follows: ##Code Start mat_zeroless<-matrix(NA,5000,2000) #genera...
2006 Dec 05
5
if(){} else{}
Dear R-community, my data set looks like 'mat' below. Plant<-c(NA,1,1,1,NA,NA,NA,NA,NA,1); Value1<-rnorm(1:10); Value2<-rnorm(1:10); mat<-cbind(Plant,Value1,Value2); I receive data from two different sites. One site is identified by an interger number, the other site has no data in column Plant=NA. My pb: I'm trying to a...
2006 Jul 20
2
Timing benefits of mapply() vs. for loop was: Wrap a loop inside a function
...ist: Thank you for the replies to my post yesterday. Gabor and Phil also gave useful replies on how to improve the function by relying on mapply rather than the explicit for loop. In general, I try and use the family of apply functions rather than the looping constructs such as for, while etc as a matter of practice. However, it seems the mapply function in this case is slower (in terms of CPU speed) than the for loop. Here is an example. # data needed for example items <- list(item1 = c(0,1,2), item2 = c(0,1), item3 = c(0,1,2,3,4), item4 = c(0,1), item5=c(0,1,2,3,4), item6=c(0,1,2,3)) sc...
2007 Jun 06
1
error message: only first element in each line of matrix used
I have a matrix and am trying to write a code to 1. identify all neg values along each line 2. for each neg value I need to identify min(j+3) 3. end with this code: eq[i,j]<- ifelse(mat.r[i,j] < (0.5*mat.s[i,j]), mat.all[i,j], 0) This is the code I have so far. I have tried several different methods but...
2000 Aug 21
4
Excluding rows from a matrix
Hi I have a matrix (4 x 950) and I want to remove 3 rows, where the values from the first column are 713, 714 and 715. I can select the rows, one by one, with mat[mat$first==713,] mat[mat$first==714,] ... but I'm unable to (i) select the 3 rows at once, (ii) select the matrix excluding those rows. How can I...
2001 Aug 19
2
error message in chol() (PR#1061)
Full_Name: Jerome Asselin Version: 1.3.0 OS: Windows 98 Submission from: (NULL) (24.77.112.193) I am having accuracy problems involving the computation of inverse of nonnegative definite matrices with solve(). I also have to compute the Choleski decomposition of matrices. My numerical problems involving solve() made me find a bug in the chol() function. Here is an example. #Please, load the (8x8) matrix "mat" given below. #The matrix "mat" is indeed invertible as s...
2005 Feb 04
4
Building a Matrix
Dear List: I am having some difficulty constructing a matrix that must take a specific form. The matrix must be have a lower block of non-zero values and the rest must all be zero. For example, if I am building an n X n matrix, then the first n/2 rows need to be zero and the first n/2 columns must remain as zero with all other elements having a non-zero v...
2009 Jan 07
0
How-To extract data from a matrix of lists subject to a set of given constraints
My goal is to store the DWT coefficients from a number of time series in such a way to be able to extract subsets satisfying giben conditions. I have defined the following 11 matrices whose x-axis represent time intervals and y-axis represent the number of time series: MS <- 11 d1.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-1)) d2.mat <- matrix (data=list(), nrow=TotNumCycles, ncol=2^(MS-3)) d3.mat <- matrix (data=list(), nrow=To...
2010 Aug 26
3
Help with ddply to eliminate a for..loop
...ut despite playing with the baseball examples quite a bit I can't figure out how to get it to work with my sample dataset. TIA for any help, Roger Here is the sample code: dat <- data.frame(id=rep(letters[1:5],3), time=c(rep(1,5),rep(2,5),rep(3,5)), slope=1:15) dat for (i in 1:3) { mat <- dat[dat$time==i, ] outi <- data.frame(mat$time, mat$id, slope=scale(mat$slope)) if (i==1) { out <- outi } else { out <- rbind(out, outi) } } out Here is the sample output: > dat <- data.frame(id=rep(letters[1:5],3), time=c(rep(1,5),rep(2,5),rep...
2004 Jul 30
2
pairwise difference operator
There was a BioConductor thread today where the poster wanted to find pairwise difference between columns of a matrix. I suggested the slow solution below, hoping that someone might suggest a faster and/or more elegant solution, but no other response. I tried unsuccessfully with the apply() family. Searching the mailing list was not very fruitful either. The closest I got to was a cryptic chunk of code in pair...