search for: mymatrix

Displaying 20 results from an estimated 87 matches for "mymatrix".

2009 Jul 20
1
S4 method dispatch with inheritance
Hi, I'm trying to create a new S4 class (myMatrix) which for now just extends dgCMatrix (from package Matrix). Then I want to use "[" which is defined in Matrix. Out of the box with "[" (defined in Matrix) I lose the class information and the result is an object of class dgCMatrix. If I specify a "["-method for m...
2013 Jun 27
3
using "rollapply" to calculate a moving sum or running sum?
#using "rollapply" to calculate a moving sum or running sum? #I am tryign to use rollapply to calcualte a moving sum? #I tried rollapply and get the error message #"Error in seq.default(start.at, NROW(data), by = by) : # wrong sign in 'by' argument" #example: mymatrix <- ( matrix(data=1:100, nrow=5, ncol=20) ) mymatrix_cumsum <- ( matrix(data=NA, nrow=5, ncol=20) ) w=12 for(i in 1: (ncol(mymatrix)-w+1) ) { mymatrix_cumsum[ , i] <- apply(X=mymatrix[, i:(i+w-1)] , MARGIN=1, FUN=sum, na.rm=T) } #How might I use the "rollapply" function instead...
2005 Jan 21
6
Avoiding a Loop?
...known. The second column is the result of multiplying this first column with a constant "const". The third column is the result of multiplying the second column with "const"..... So far, I did it like this (as a simplified example): nr.of.columns <- 4 myconstant <- 27.5 mymatrix <- matrix(numeric(0), nrow=5, ncol=nr.of.columns) mymatrix[,1] <- 1:5 for (i in 2:nr.of.columns) { mymatrix[,i] <- myconstant * mymatrix[,i-1] } Can anyone give me some advice whether it is possible to avoid this loop (and if yes: how)? Any suggestions are welcome! Thanks, Roland...
2012 Aug 01
1
Error message: $ operator is invalid for atomic vectors
HI, The code was working perfectly fine yesterday and today, until half an hour ago.? Couldn't find any problems in the code. Still, I am getting error message. myMatrix <- data.matrix(read.table(text=" Name??????????? Age ANTONY??????? 27 IMRAN????????? 30 RAJ????????????????? 22 NAHAS????????? 32 GEO??????????????? 42 ", header=TRUE)) MinMaxArray? <- data.frame(MIN = 25,MAX=35) myMatrix[myMatrix$Age<=MinMaxArray$MAX & myMatrix$Age>=MinM...
2005 Feb 21
3
Sorting a matrix on two columns
Hello, If a matrix with 5 columns has been defined and the first two columns need to be sorted in ascending order, how can this be achieved whilst ensuring the other 3 columns data are in relative position to the sorted columns? Glen Jones [[alternative HTML version deleted]]
2006 Apr 04
2
Selecting out certain values from a MATRIX
I have two objects, one matrix and one vector. I want to use my vector to subset certain values out of my matrix. For example: I want to tell R, to select out all rows in myMatrix into a new myMatrix2 IF that corresponding row is less than a 0.5 in myVector. So: myMatrix = a matrix of 8000 by 20 myVector = vector of 8000 myMatrix2 = a matrix of < 8000 by 20 (based on selection criteria in myVector) I hope this makes sense.. [[alternative HTML version deleted]]
2004 Nov 01
5
make apply() return a list
...ices have all the same dimension. To get a list I could change the dimension of one matrix artificially and restore it after apply(): This a (very much) simplified example of what I did: > myData <- data.frame( a = c( 1,2,3 ), b = c( 4,5,6 ) ) > myFunction <- function( values ) { + myMatrix <- matrix( values, 2, 2 ) + if( all( values == myData[ 1, ] ) ) { + myMatrix <- cbind( myMatrix, rep( 0, 2 ) ) + } + return( myMatrix ) + } > myList <- apply( myData, 1, myFunction ) > myList[[ 1 ]] <- myList[[ 1 ]][ 1:2, 1:2 ] > myList $"1" [,1] [...
2005 Aug 08
2
computationally singular
Hi, I have a dataset which has around 138 variables and 30,000 cases. I am trying to calculate a mahalanobis distance matrix for them and my procedure is like this: Suppose my data is stored in mymatrix > S<-cov(mymatrix) # this is fine > D<-sapply(1:nrow(mymatrix), function(i) mahalanobis(mymatrix, mymatrix[i,], S)) Error in solve.default(cov, ...) : system is computationally singular: reciprocal condition number = 1.09501e-25 I understand the error message but I don't know how t...
2011 Oct 11
2
binding all elements of list (character vectors) to a matrix as rows
dear r-users, i have got a problem which i am trying to solve: i have got the following commands: Mymatrix <- matrix(1:9,ncol=3) Z <- list("V1"=c("a","",""),"V2"=c("b","",""),"V3"=c("c","",""),"V4"=c("d","","")) Mymatrix <- rbind(Mymatri...
2012 Jul 31
2
Remove a complete row as per the Range in a Matrix
Hi, Here i have a Matrix MyMatrix <- Name Age --------- ------- ANTONY 27 IMRAN 30 RAJ 22 NAHAS 32 GEO 42 and here i have an array with Minimum and Maximum values. MinMaxArray <- data.frame(MIN = 25,MAX=35) MIN MAX ------ -------- 2...
2011 Aug 17
2
Lattice: problem with setting space between plot and legend
...resent my output data (I'm using Lattice Package). However, it's essential for me to control space between barchart and legend. I've read the package's specification, but unfortunately I haven't spot the information how to do this. Here's the code I've written: barchart(mymatrix[,1:ncol(mymatrix)],horizontal=FALSE, box.width=1,stack=TRUE,border=FALSE,par.settings = simpleTheme(col =my_colors),lty="dotted",lend="butt",key=list(space="bottom",columns=ncol(mymatrix),points=FALSE,text=list(colnames(mymatrix)),rectangles=list(border=FALSE,size=2,c...
2008 May 21
2
Converting Data Types
Hi, How can I convert the matrices to list. For example I have this snippet: samples<-mymatrix[1,] print(samples) which prints: V1 V2 V3 V4 V5 V6 1 103.9 88.5 242.9 206.6 175.7 164.4 How can I convert the object "samples" such that it prints: [1] 103.9 88.5 242.9 206.6 175.7 164.4 The reason I ask this because I can't use the former "samples" o...
2006 Mar 16
6
removing ROWS with missing values
I am trying to find out if R can recognize specific criteria for removing rows (i.e. a prexisting function) I have a matrix myMatrix that is 12000 by 20 I would like to remove rows from myMatrix that have: -999 across all columns -999 across all columns but one -999 across all columns but two -999 across all columns but three -999 across all columns but four -999 across all columns but five (-999 here is my missing value) Do...
2007 Feb 12
3
processing a large matrix
I would like to compare every column in my matrix with every other column and get the r-squared. I tried using the following formula and looping through every column: > summary(lm(matrix[,x]~matrix[,y]))$r.squared If I have 10,000 columns, the loops (10,000 * 10,000) take forever even if there is no formula inside. Then, I attempted to vectorize my code: > cor(matrix)^2 With 10,000
2005 Dec 08
3
Reshaping data
...place=FALSE), no=sample(1:10, size=n, replace=FALSE)) Now I would like to make a matrix with (in this simple example) 10 columns (for the years) and 12 rows (for the ages). In each cell, I would like to put the correct number of individuals. So far I was doing this as follows: mymatrix <- matrix(0, ncol=10, nrow=12) for (year in unique(mydf$yr)) { for (age in unique(mydf$age)) { if (length(mydf$no[mydf$yr==year & mydf$age==age]) > 0) { mymatrix[age,year] <- mydf$no[mydf$yr==year & mydf$age==age] } else { mymatrix[age,year] <- 0 } }...
2012 Jul 30
6
Convert variable to STring
Dear all, I have a variable that I would like also to use it as a string. The reasons is that I want to collect results from different function to one table.. So when I use the  colnames(mymatrix) <-c(function1.function2,function3) the function1, function2, function3 to be "converted" to simple strings so as  colnames(mymatrix) <-c("function1","function2","function3") Could you please help me understand how I can do that in R? Regards [[alt...
2006 Aug 09
3
objects and environments
Dear list, I have two functions created in the same environment, fun1 and fun2. fun2 is called by fun1, but fun2 should use an object which is created in fun1 fun1 <- function(x) { ifelse(somecondition, bb <- "o", bb <- "*") ## mymatrix is created, then myresult <- apply(mymatrix, 1, fun2) } fun2 <- function(idx) { if (bb == "o) { # do something with idx } else { # do something else with idx } } What should I do to have "bb" available in fun2? I tried everything I could with sys.pare...
2012 Jul 19
2
Line chart with a double matrix
Hello, I have a double matrix that I want to represent in a line chart. Although I have seen some examples I still don't manage to get it. My data is this (a double matrix called mymatrix) : Blogs Wikis Redes Etiq. SPC LMS Menor de 30 57.14 28.57 14.29 28.57 57.14 28.57 de 31 a 40 63.83 61.70 29.79 17.02 59.57 70.21 de 41 a 50 72.64 70.75 47.17 20.75 55.66 75.47 Mayor de 51 62.07 58.62 48.28 17.24 50.00 67.24 As I understand from http://www.statmethods.net/graph...
2012 Jun 14
3
Time difference between two dates/timing
Hi, Here, i have a matrix like this MyMatrix <- *DATETIME HEADER1 HEADER2* 1/1/2010 0:10 197.1947 100.0859 1/1/2010 0:20 203.8811 100.1013 1/1/2010 0:30 206.564 100.0433 1/1/2010 0:40 207.9563 99.9393 i want to get the time difference in minutes between two date. TimeDif...
2012 Mar 20
1
Remove individual rows from a matrix based upon a list
...ual (row) excluded in each instance. That individual would be returned to the matrix before the next is removed and the function recalculated. I can do this by hand removing rows based upon ids however I would like specify individuals to be removed from a list (lots of data). An example matrix: MyMatrix E985047 E985071 E985088 F952477 F952478 J644805 J644807 J644813 E985047 1 0.09 0 0 0 0 0 0.4 E985071 0.09 1 0 0 0 0 0 0.07 E985088 0 0 1 0 0 0 0.14 0 F952477 0 0 0 1 0.38 0 0 0 F952478 0 0 0 0.38 1 0 0 0 J644805 0 0 0 0 0 1 0.07 0 J644807 0 0 0.14 0 0 0.07 1 0 J644813 0.4 0.07 0 0 0 0 0...