Re: [R] Matrix - querying dsCMatrix how to save it

2024-11-11 Thread Martin Maechler
I was asked privately > I have been using extensively to > calculate the relatedness-matrix based on the pedigree for > our ornamental plants. I was wondering if you could give > me some advice, for which I would like to thank you in > advance! > The output of the relate

Re: [R] Matrix scalar operation that saves memory?

2023-04-13 Thread Richard O'Keefe
"wear your disc quite badly"? If you can afford a computer with 512 GB of memory, you can afford to pay $100 for a 2 TB external SSD, use it as scratch space, and throw it away after a month of use. A hard drive is expected to last for more than 40,000 hours of constant use. Are you sure that you

Re: [R] Matrix scalar operation that saves memory?

2023-04-11 Thread Iago Giné Vázquez
De: R-help de part de Eric Berger Enviat el: dimecres, 12 d’abril de 2023 8:38 Per a: Bert Gunter A/c: R-help Tema: Re: [R] Matrix scalar operation that saves memory? One possibility might be to use Rcpp. An R matrix is stored in contiguous memory, which can be considered as a

Re: [R] Matrix scalar operation that saves memory?

2023-04-11 Thread Eric Berger
One possibility might be to use Rcpp. An R matrix is stored in contiguous memory, which can be considered as a vector. Define a C++ function which operates on a vector in place, as in the following: library(Rcpp) cppFunction( 'void subtractConst(NumericVector x, double c) { for ( int i = 0; i

Re: [R] Matrix scalar operation that saves memory?

2023-04-11 Thread Bert Gunter
I doubt that R's basic matrix capabilities can handle this, but have a look at the Matrix package, especially if your matrix is some special form. Bert On Tue, Apr 11, 2023, 19:21 Shunran Zhang wrote: > Hi all, > > I am currently working with a quite large matrix that takes 300G of > memory. My

Re: [R] Matrix scalar operation that saves memory?

2023-04-11 Thread Shunran Zhang
Thanks for the info. For the data type, my matrix as of now is indeed a matrix in a perfect square shape filled in a previous segment of code, but I believe I could extract one row/column at a time to do some processing. I can also change that previous part of code to change the data type of i

Re: [R] Matrix scalar operation that saves memory?

2023-04-11 Thread avi.e.gross
The example given does not leave room for even a single copy of your matrix so, yes, you need alternatives. Your example was fairly trivial as all you wanted to do is subtract each value from 100 and replace it. Obviously something like squaring a matrix has no trivial way to do without multiple c

Re: [R] Matrix::solve() with 1-d arrays -- treating "array" as "numeric"?

2021-04-19 Thread Martin Maechler
> Deepayan Sarkar > on Mon, 19 Apr 2021 09:56:58 +0530 writes: > On Sat, Apr 17, 2021 at 9:08 PM Martin Maechler > wrote: >> >> > Deepayan Sarkar > on Fri, 16 Apr 2021 11:34:20 >> +0530 writes: >> >> > I get what I initially thought was unexpecte

Re: [R] Matrix::solve() with 1-d arrays -- treating "array" as "numeric"?

2021-04-18 Thread Deepayan Sarkar
On Sat, Apr 17, 2021 at 9:08 PM Martin Maechler wrote: > > > Deepayan Sarkar > > on Fri, 16 Apr 2021 11:34:20 +0530 writes: > > > I get what I initially thought was unexpected behaviour from: > > > x <- tapply(runif(100), sample(5, 100, TRUE), mean) > > solve(Diagonal(5), x

Re: [R] Matrix::solve() with 1-d arrays -- treating "array" as "numeric"?

2021-04-17 Thread Martin Maechler
> Deepayan Sarkar > on Fri, 16 Apr 2021 11:34:20 +0530 writes: > I get what I initially thought was unexpected behaviour from: > x <- tapply(runif(100), sample(5, 100, TRUE), mean) > solve(Diagonal(5), x) > # Error: not-yet-implemented method for solve(, ). > # -

Re: [R] Matrix - remove [,1] from top row

2019-07-02 Thread Richard O'Keefe
(1) m[,1] is the first column of matrix (or dataframe) m. (2) The first row of matrix or dataframe m is m[1,] (3) To remove the first row of matrix or dataframe m, do m <- m[-1,] On Wed, 3 Jul 2019 at 08:59, Nicola Cecchino wrote: > Hello, > > I am simply trying to remove the [,1] row from

Re: [R] Matrix - remove [,1] from top row

2019-07-02 Thread Richard M. Heiberger
give your a matrix an empty column name. > tmp <- matrix(1:4, 4, 1, dimnames=list(letters[1:4], NULL)) > tmp [,1] a1 b2 c3 d4 > dimnames(tmp)[[1]] [1] "a" "b" "c" "d" > dimnames(tmp)[[2]] NULL > dimnames(tmp)[[2]] <- "" > tmp a 1 b 2 c 3 d 4 On Tue, Jul 2, 2019 at 5:09 PM wrot

Re: [R] Matrix - remove [,1] from top row

2019-07-02 Thread ruipbarradas
Hello, That is not a row, what you seem to have is an object of class "matrix" and when it's printed it prints the column names or [,1] [,2] etc if there aren't any colnames. So your matrix has just one column and 4 rows with rownames 'date', 'Peeps', 'days', 'worn'. Hope this helps, R

Re: [R] Matrix::bdiag doesn't like being given a single named argument

2019-05-31 Thread Jeff Newmiller
My take would be that there is no reason to specify argument names at all when calling bdiag, and clearly there is a reason to not do so. The error seems to arise from using the S3 method is.list, which allows your final example to work. is.list(a=1) clearly fails to match the x argument, but i

Re: [R] matrix subset problem with factors

2019-02-20 Thread Jeff Newmiller
With on official weight, I second the opinion that the existing behavior is appropriate and not a bug. Functions should not "unexpectedly" return factors... a common example are the read.table family of functions that by default return factors, but the behaviour is deterministic and controllabl

Re: [R] matrix subset problem with factors

2019-02-20 Thread Marc Schwartz via R-help
Hi, I get the same behavior in R 3.5.2 on macOS. Others may feel differently, but I am not so sure that this is a bug, as opposed to perhaps the need to clarify in ?Extract, that the following, which is found under Atomic vectors: "The index object i can be numeric, logical, character or empty

Re: [R] Matrix logical operator

2017-07-16 Thread Berend Hasselman
> On 17 Jul 2017, at 07:27, Jeremie Juste wrote: > > > Hello, > > I have some trouble understanding why !b &&TRUE is TRUE. Do you have an idea? > > >> b <- matrix(c(0,1,1,0,1,0),2) > >> !b > [,1] [,2] [,3] > [1,] TRUE FALSE FALSE > [2,] FALSE TRUE TRUE >> !b &&TRUE > [1] TRUE >

Re: [R] Matrix multiplication

2017-06-07 Thread Jeff Newmiller
Fine, except that you already seen to have a very compact solution if that really is what you are looking for. What am I missing? -- Sent from my phone. Please excuse my brevity. On June 7, 2017 9:16:48 PM PDT, Steven Yen wrote: >OK Thanks. Your response made me think. Here (the last line) is

Re: [R] Matrix multiplication

2017-06-07 Thread Steven Yen
OK Thanks. Your response made me think. Here (the last line) is what I need: set.seed(76543211) w<-1:10; w a<-matrix(rpois(20,2),nrow=10); a t(w*a)%*%a On 6/8/2017 12:09 PM, Jeff Newmiller wrote: > Is this a question? You seem to have three possible calculations, have > already implemented two o

Re: [R] Matrix multiplication

2017-06-07 Thread Jeff Newmiller
Is this a question? You seem to have three possible calculations, have already implemented two of them (?) and it is unclear (to me) what you think the right answer for any of them is supposed to be. -- Sent from my phone. Please excuse my brevity. On June 7, 2017 8:50:55 PM PDT, Steven Yen w

Re: [R] Matrix-list table conversion+nrwos with specefic values.

2017-04-29 Thread Jeff Newmiller
mber of column of the >matrix. > >Please let me know if this is not clear. > > >Many thanks > > > >From: Jeff Newmiller >Sent: 29 April 2017 10:11 PM >To: r-help@r-project.org; Bert Gunter; abo dalash; R-help >Subject: Re: [

Re: [R] Matrix-list table conversion+nrwos with specefic values.

2017-04-29 Thread Jeff Newmiller
Break it down. If you have a scalar value val and you want to know if it is in a vector vec, using val==vec gets you a logical vector as long as vec. You can use val %in% vec and you get a logical vector as long as val (e.g. 1). If val is a vector of, say, length 2, then you will get a length 2

Re: [R] Matrix-list table conversion+nrwos with specefic values.

2017-04-29 Thread Bert Gunter
I am not a private (or free!) consultant. Post to the r-help if your question concerns R. -- Bert Bert Gunter On Sat, Apr 29, 2017 at 8:51 AM, abo dalash wrote: > Hi dear Bert > > > I'm trying to identify number of rows containing 2 specific values. > > I tried : which(mydata == 566,235), but

Re: [R] matrix merge, or something else?

2017-03-10 Thread Evan Cooch
Slick -- thanks. On 3/10/2017 1:26 AM, Jeff Newmiller wrote: test2[ , colnames( test1 ) ] <- test1 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http

Re: [R] matrix merge, or something else?

2017-03-09 Thread Jeff Newmiller
test2[ , colnames( test1 ) ] <- test1 -- Sent from my phone. Please excuse my brevity. On March 9, 2017 6:56:13 PM PST, Evan Cooch wrote: >Suppose I have the following two matrices, both with same number of >rows >(3), but different number of columns (3 in test1, 4 in test2). > >test1 <- matrix

Re: [R] Matrix

2017-03-07 Thread David L Carlson
lson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Gabor Grothendieck Sent: Tuesday, March 7, 2017 7:21 AM To: Peter Thuresson Cc: R-help@r-project.org Subject: Re: [R] M

Re: [R] Matrix

2017-03-07 Thread Gabor Grothendieck
Assuming that the input is x <- 1:4, try this one-liner: > embed(c(0*x[-1], x, 0*x[-1]), 4) [,1] [,2] [,3] [,4] [1,]1000 [2,]2100 [3,]3210 [4,]4321 [5,]0432 [6,]0043 [7,]0004 On Mo

Re: [R] Matrix

2017-03-06 Thread Richard M. Heiberger
## 1. ## This could be captured into a function tmp <- matrix(0, 7, 4) tmp diag(tmp) <- 1 diag(tmp[-1,]) <- 2 diag(tmp[-(1:2),]) <- 3 diag(tmp[-(1:3),]) <- 4 tmp ## 2. v <- 1:4 v2 <- c(v, rep(0, length(v))) ## this generates a warning that can safely be ignored (or turned off) matrix(v2, length(

Re: [R] Matrix

2017-03-06 Thread Mathew Guilfoyle
Effectively you want a circulant matrix but filled by column. Example input vector and number of columns x = c(1:8,19:20) nc = 5 For the result you specifically describe, the following generalises for any vector and any arbitrary number of columns 'nc', padding with zeros as necessary. matrix

Re: [R] Matrix

2017-03-06 Thread Bert Gunter
Well, of course, I *did* make a dumb error (again!!). Here's the corrected version: x <- c(1:5,10:12) ## generate vector of indices by outer and %% i <- seq_along(x) nc <- 4 ## number of columns desired Corrected statement indx <- (outer(i, rev(i-1),"+") %% length(x)) [,seq_len(nc)] +1

Re: [R] Matrix

2017-03-06 Thread Bert Gunter
Clever, Don. Here's a more explicit approach that generalizes (if I haven't made any dumb errors): x <- c(1:5,10:12) ## generate vector of indices by outer and %% i <- seq_along(x) nc <- 4 ## number of columns desired ## get subscripting indices via outer() and %% indx <- outer(i,rev(i),"+") %% (

Re: [R] Matrix

2017-03-06 Thread Rui Barradas
Hello, Try the following. proj <- function(x){ n <- length(x) y <- numeric(n) z <- rep(c(x, y), times = n) z <- z[-((length(z) - n + 1):length(z))] matrix(z, ncol = n) } proj(1:4) proj(1:5) Hope this helps, Rui Barradas Em 06-03-2017 16:18, Peter Thure

Re: [R] Matrix

2017-03-06 Thread MacQueen, Don
How about this: p0 <- 1:4 matrix( c( rep( c(p0, rep(0, 4)) , times=3) , p0) , 7, 4) Of course, it would take some effort to generalize it to different lengths for p0. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 3/6/

Re: [R] Matrix

2016-07-17 Thread David Winsemius
> On Jul 16, 2016, at 7:43 PM, Ashta wrote: > > HI Denes, Duncan,Michael and all, > > Thank you very much for the helpful suggestion. Some of my data sets > were not square matrix, however, Denes's suggestion," > as.data.frame.table() ", handled that one. > `as.data.frame.table` should work

Re: [R] Matrix

2016-07-16 Thread Ashta
HI Denes, Duncan,Michael and all, Thank you very much for the helpful suggestion. Some of my data sets were not square matrix, however, Denes's suggestion," as.data.frame.table() ", handled that one. Thank you again. On Sat, Jul 16, 2016 at 7:27 PM, Dénes Tóth wrote: > > > On 07/17/2016 01:3

Re: [R] Matrix

2016-07-16 Thread Dénes Tóth
On 07/17/2016 01:39 AM, Duncan Murdoch wrote: On 16/07/2016 6:25 PM, Ashta wrote: > Hi all, > > I have a large square matrix (60 x 60) and found it hard to > visualize. Is it possible to change it as shown below? > > Sample example (3 x 3) > > A B C > A 3 4 5 > B 4 7

Re: [R] Matrix

2016-07-16 Thread Michael Hannon
I'm not sure what the OP is looking for in the first two columns, but he does seem to be looking for only the diagonal and super-diagonal elements. Here's some code that makes output that looks similar to the "Desired output": mat1 <- matrix(rbind(c(3, 4, 5), c(4, 7, 8),

Re: [R] Matrix

2016-07-16 Thread Duncan Murdoch
On 16/07/2016 6:25 PM, Ashta wrote: > Hi all, > > I have a large square matrix (60 x 60) and found it hard to > visualize. Is it possible to change it as shown below? > > Sample example (3 x 3) > > A B C > A 3 4 5 > B 4 7 8 > C 5 8 9 > > Desired output > A A 3 > A B 4 >

Re: [R] matrix indexing/subset error

2016-05-30 Thread Jeff Newmiller
z %% 2 == 1 has 12 logical values. What do you expect R to do with it worth respect to 4 rows? -- Sent from my phone. Please excuse my brevity. On May 30, 2016 11:38:46 AM PDT, Carl Sutton via R-help wrote: >Hi Guru's >In my quest to understand R I have what I thought was a simple exercise

Re: [R] Matrix multiplications

2016-05-21 Thread george brida
Thank you very much Peter. On Sat, May 21, 2016 at 9:18 PM, peter dalgaard wrote: > > > On 21 May 2016, at 21:00 , george brida wrote: > > > > Dear R users: > > > > I have written the following lines : > > > >> x=c(10,11,12,13,14,17,15,16,10,11,41,25,26,14,12,14,15,20,14,22) > >> x=matrix(x,nco

Re: [R] Matrix multiplications

2016-05-21 Thread peter dalgaard
I don't know if there is some sort of propagation delay, but the reason has already been given and multiple fixes suggested. -pd > On 21 May 2016, at 21:26 , george brida wrote: > > Roy, > > Yes, t(y-X %*% b) is the transpose of y-X %*% b. In principle the product > of t(y-X %*% b) *(y-X %*

Re: [R] Matrix multiplications

2016-05-21 Thread george brida
Roy, Yes, t(y-X %*% b) is the transpose of y-X %*% b. In principle the product of t(y-X %*% b) *(y-X %*% b) is a scalar, I don't know why I have an error message after the following line: (t(y-X %*% b)%*%(y-X %*% b)/(length(y)-ncol(X)))*solve(t(X)%*% X) Thanks On Sat, May 21, 2016 at 9:10 PM,

Re: [R] Matrix multiplications

2016-05-21 Thread peter dalgaard
> On 21 May 2016, at 21:00 , george brida wrote: > > Dear R users: > > I have written the following lines : > >> x=c(10,11,12,13,14,17,15,16,10,11,41,25,26,14,12,14,15,20,14,22) >> x=matrix(x,ncol=2) >> a=matrix(1,nrow(x),1) >> X=cbind(a,x) >> y=c(12.00, 11.00, 13.00, 12.50, 14.00, 18.50, 15.0

Re: [R] Matrix multiplications

2016-05-21 Thread Roy Mendelssohn - NOAA Federal
> str(t(y-X %*% b)) num [1, 1:10] 0.595 -1.7538 -0.0498 -1.651 -0.6328 ... > str((y-X %*% b)) num [1:10, 1] 0.595 -1.7538 -0.0498 -1.651 -0.6328 … -Roy > On May 21, 2016, at 12:00 PM, george brida wrote: > > Dear R users: > > I have written the following lines : > >> x=c(10,11,12,13,14,17

Re: [R] Matrix: How create a _row-oriented_ sparse Matrix (=dgRMatrix)?

2016-04-20 Thread Henrik Bengtsson
On Wed, Apr 20, 2016 at 1:25 AM, Martin Maechler wrote: >> Henrik Bengtsson >> on Tue, 19 Apr 2016 14:04:11 -0700 writes: > > > Using the Matrix package, how can I create a row-oriented sparse > > Matrix from scratch populated with some data? By default a > > column-orien

Re: [R] Matrix: How create a _row-oriented_ sparse Matrix (=dgRMatrix)?

2016-04-20 Thread Martin Maechler
> Henrik Bengtsson > on Tue, 19 Apr 2016 14:04:11 -0700 writes: > Using the Matrix package, how can I create a row-oriented sparse > Matrix from scratch populated with some data? By default a > column-oriented one is created and I'm aware of the note that the > packag

Re: [R] Matrix summary

2016-02-12 Thread Bert Gunter
Yes, but colMeans, rowMeans, pmax, pmin , etc. are *much* faster. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Feb 12, 2016 at 9:15 PM, J

Re: [R] Matrix summary

2016-02-12 Thread Jim Lemon
Hi Ashta, Surely you are aware of the "apply" family of functions that return the numbers you want: ashmat<-matrix(c(117,12,13,21,21,32,11,1,65,43,23,7,58,61,78,95 ), nrow=4,byrow=TRUE) apply(ashmat,2,mean) [1] 65.25 37.00 31.25 31.00 apply(ashmat,1,which.max) [1] 1 2 1 4 Jim On Sat, Feb 13, 2

Re: [R] Matrix of Lists containing numbers and characters

2016-01-25 Thread PIKAL Petr
Hi What is Temp? Just a guess. "model" variable is factor and it is converted to its numeric representation during paste or any other operation you made. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of TJUN > KIAT TEO > Sent: Monday, J

Re: [R] matrix which results singular but at the same time positive definite

2015-12-28 Thread Stefano Sofia
Da: Paul Gilbert [pgilbert...@gmail.com] Inviato: martedì 15 dicembre 2015 15.28 A: Stefano Sofia Cc: r-help@r-project.org; Fox, John; peter dalgaard Oggetto: Re: [R] matrix which results singular but at the same time positive definite Stefano I think in other response to in this thread you got

Re: [R] matrix which results singular but at the same time positive definite

2015-12-15 Thread Paul Gilbert
Stefano I think in other response to in this thread you got the answer to the question you asked, but you may be asking the wrong question. I'm not familiar with the specific papers you mention and you have not provided enough detail about what you are doing, so I am guessing a bit. The term

Re: [R] matrix which results singular but at the same time positive definite

2015-12-14 Thread Stefano Sofia
-project.org Oggetto: RE: [R] matrix which results singular but at the same time positive definite Dear Peter, > -Original Message- > From: peter dalgaard [mailto:pda...@gmail.com] > Sent: Thursday, December 10, 2015 11:09 AM > To: Stefano Sofia > Cc: Fox, John; r-help@r-projec

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Fox, John
Dear Peter, > -Original Message- > From: peter dalgaard [mailto:pda...@gmail.com] > Sent: Thursday, December 10, 2015 11:09 AM > To: Stefano Sofia > Cc: Fox, John; r-help@r-project.org > Subject: Re: [R] matrix which results singular but at the same time > positiv

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread peter dalgaard
Looks like the ill-conditioning is almost entirely due to scaling, e.g. > eigen(cov2cor(m)) $values [1] 1.7234899 1.3380701 0.6619299 0.2765101 ... This is an annoyance in several parts of numerical linear algebra: Routines assume that R^n has all coordinates on a similar scale and therefore thi

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Fox, John
Dear Stefano, I don't really know anything about your application, but my point is about the scaling of the variables. Can't you rescale some or all of the variables so their variances aren't so different? For example, the correlation matrix among these four variables isn't ill-conditioned. Be

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Stefano Sofia
Dear John, thank you for your considerations. This matrix (which is a variance matrix) is part of an algorithm for forward-filtering and backward-sampling of Dynamic Linear Models (West and Harrison, 1997), applied to DLM representation of ARIMA processes (Petris, Petrone, Campagnoli). It is th

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Fox, John
Dear Stefano, You've already had a couple of informative responses directly addressing your question, but are you aware how ill-conditioned the matrix is (one of the responses alluded to this)? > kappa(X, exact=TRUE) [1] 7.313338e+12 > eigen(X)$values [1] 4.964711e+00 9.356881e-01 4.863392e-12

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Rolf Turner
On 10/12/15 23:08, Stefano Sofia wrote: Dear list users, through the "matrixcalc" package I am performing some checks of variance matrices (which must be positive definite). In this example, it happens that the matrix A here reported is singular but positive definite. Is it possible?

Re: [R] matrix which results singular but at the same time positive definite

2015-12-10 Thread Giorgio Garziano
Decrease the "tol" parameter specified into the "is.non.singular.matrix() call, for example as: m <- matrix(c( 1.904255e-12, -1.904255e-12, -8.238960e-13, -1.240294e-12, -1.904255e-12, 3.637979e-12, 1.364242e-12, 1.818989e-12, -8.238960e-13, 1.364242e-12, 4.80998

Re: [R] Matrix element-by-element multiplication

2015-09-29 Thread David Winsemius
On Sep 29, 2015, at 4:49 PM, waddawanna wrote: > Hello Steven, > > It looks like, there is no in-built function that can do GAUSS ".*" > element-wise multiplication. > Now, if you want to make the desired computations in R, it is actually > preatty straightforward. > >> a<-c(1,2,3) >> b<-matrix

Re: [R] Matrix element-by-element multiplication

2015-09-29 Thread Rolf Turner
On 30/09/15 12:49, waddawanna wrote: Hello Steven, It looks like, there is no in-built function that can do GAUSS ".*" element-wise multiplication. Now, if you want to make the desired computations in R, it is actually preatty straightforward. a<-c(1,2,3) b<-matrix(rep(1:9,1),3,3,byrow=TRUE) a

Re: [R] matrix manipulation -solved

2015-07-16 Thread Therneau, Terry M., Ph.D.
Yes it is obvious --- once someone else pointed it out. Thanks for the hint. Terry T. On 07/16/2015 12:52 PM, Peter Langfelder wrote: Hi Terry, maybe I'm missing something, but why not define a matrix BB = V'B; then t(B) %*% V = t(BB), then your problem reduces to finding A such that t(BB) %*

Re: [R] matrix manipulation

2015-07-16 Thread Peter Langfelder
Hi Terry, maybe I'm missing something, but why not define a matrix BB = V'B; then t(B) %*% V = t(BB), then your problem reduces to finding A such that t(BB) %*% A = 0? Peter On Thu, Jul 16, 2015 at 10:28 AM, Therneau, Terry M., Ph.D. wrote: > This is as much a mathematics as an R question, in t

Re: [R] Matrix Manipulation R

2015-07-04 Thread David Winsemius
> On Jul 4, 2015, at 3:09 AM, Alex Kim wrote: > > Hi guys, > > Suppose I have an extremely large data frame with 2 columns and .5 mil > rows. For example, the last 6 rows may look like this: > . > .. > ... > 89 100 > 93 120 > 95 125 > 101NA > 115NA > 123

Re: [R] matrix -> delete last row -> list

2015-07-04 Thread Michael Sumner
Well 'list' in R is pretty naturally the same as R's 'atomic vector' in scads of languages. In R the term needs special care since it's still a 'vector'. 'Degenerate dimension' is probably a helpful phrase for understanding what is happening here. Cheers, Mike On Saturday, July 4, 2015, Rolf Tur

Re: [R] matrix -> delete last row -> list

2015-07-03 Thread Sarah Goslee
Hi, On Fri, Jul 3, 2015 at 10:33 AM, Zander, Joscha wrote: > Good day R-community, > > i just wondered if it is a bug or a feature... > > When i have a matrix "mat" with one column and i delete the last row with > > mat <- mat[-nrow(mat),] the result is a list. I have no idea how you're getting

Re: [R] matrix -> delete last row -> list

2015-07-03 Thread Marc Schwartz
> On Jul 3, 2015, at 9:33 AM, Zander, Joscha wrote: > > Good day R-community, > > i just wondered if it is a bug or a feature... > > When i have a matrix "mat" with one column and i delete the last row with > > mat <- mat[-nrow(mat),] the result is a list. > > So my next call mat[10,] will t

Re: [R] matrix/df help populate NA

2015-06-14 Thread Adrian Johnson
Thank you very much. It worked! On Sun, Jun 14, 2015 at 8:00 PM, jim holtman wrote: > Is this what you want: > >> x1 = structure(list(Subject = c("x1", "x2"), A = c(1.5, -1.2), B = c(-1.3, > + -0.3), C = c(0.4, 0.3), D = c(-0.2, -0.1)), .Names = c("Subject", > + "A", "B", "C", "D"), class = "dat

Re: [R] matrix/df help populate NA

2015-06-14 Thread jim holtman
Is this what you want: > x1 = structure(list(Subject = c("x1", "x2"), A = c(1.5, -1.2), B = c(-1.3, + -0.3), C = c(0.4, 0.3), D = c(-0.2, -0.1)), .Names = c("Subject", + "A", "B", "C", "D"), class = "data.frame", row.names = c(NA, + -2L)) > > x2 = structure(list(Subject = c("x1", "x2"), A = c(4.3,

Re: [R] matrix/df help populate NA

2015-06-13 Thread Jeff Newmiller
?merge Particularly look at the all argument. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.

Re: [R] Matrix of indexes to extract sparse data in dataframe

2015-06-05 Thread Sergio Fonda
gt; David L Carlson > Department of Anthropology > Texas A&M University > College Station, TX 77840-4352 > > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sergio > Fonda > Sent: Friday, June 5, 2015 8:47 AM > To: John Kane > Cc:

Re: [R] Matrix of indexes to extract sparse data in dataframe

2015-06-05 Thread David L Carlson
nda Sent: Friday, June 5, 2015 8:47 AM To: John Kane Cc: R-help Subject: Re: [R] Matrix of indexes to extract sparse data in dataframe Thank you, of course but I can't use that form as I told. My question is about the possibility to enter in a dataframe with a matrix of indices and get the cor

Re: [R] Matrix of indexes to extract sparse data in dataframe

2015-06-05 Thread Sergio Fonda
Thank you, of course but I can't use that form as I told. My question is about the possibility to enter in a dataframe with a matrix of indices and get the corresponding values Thanks again Il 05/giu/2015 15:39, "John Kane" ha scritto: > d1 <- apply(c0, 1, min) I think does it. > > John Kane

Re: [R] Matrix of indexes to extract sparse data in dataframe

2015-06-05 Thread John Kane
d1 <- apply(c0, 1, min) I think does it. John Kane Kingston ON Canada > -Original Message- > From: sergio.fond...@gmail.com > Sent: Fri, 5 Jun 2015 15:06:34 +0200 > To: r-help@r-project.org > Subject: [R] Matrix of indexes to extract sparse data in dataframe > > I would like to avoid

Re: [R] matrix inf and zero's value replacement

2015-05-12 Thread Uwe Ligges
On 13.05.2015 08:04, Ragia Ibrahim wrote: Dear Group, I have the following matrix m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]021 Inf Inf Inf Inf Inf [2,]102 Inf Inf Inf Inf Inf [3,]210 Inf Inf Inf Inf Inf [4,]3210 Inf

Re: [R] matrix manipulation question

2015-03-31 Thread Stéphane Adamowicz
Many thanks, Stéphane Le 30 mars 2015 à 10:42, peter dalgaard a écrit : > >> On 30 Mar 2015, at 09:59 , Stéphane Adamowicz >> wrote: >> >> >> However, in order to help me understand, would you be so kind as to give me >> a matrix or data.frame example where « complete.cases(X)== T » or «

Re: [R] matrix manipulation question

2015-03-30 Thread peter dalgaard
> On 30 Mar 2015, at 09:59 , Stéphane Adamowicz > wrote: > > > However, in order to help me understand, would you be so kind as to give me a > matrix or data.frame example where « complete.cases(X)== T » or « > complete.cases(X)== TRUE » would give some unwanted result ? The standard proble

Re: [R] matrix manipulation question

2015-03-30 Thread Berend Hasselman
> On 30-03-2015, at 09:59, Stéphane Adamowicz > wrote: > > > Le 27 mars 2015 à 18:01, David Winsemius a écrit : > >> >> On Mar 27, 2015, at 3:41 AM, Stéphane Adamowicz wrote: >> >>> Well, it seems to work with me. >>> >> >> No one is doubting that it worked for you in this instance. What

Re: [R] matrix manipulation question

2015-03-30 Thread Stéphane Adamowicz
Le 27 mars 2015 � 18:01, David Winsemius a �crit : > > On Mar 27, 2015, at 3:41 AM, St�phane Adamowicz wrote: > >> Well, it seems to work with me. >> > > No one is doubting that it worked for you in this instance. What Peter D. was > criticizing was the construction : > > complete.cases(t(

Re: [R] matrix manipulation question

2015-03-27 Thread Henric Winell
On 2015-03-27 11:41, Stéphane Adamowicz wrote: Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313

Re: [R] matrix manipulation question

2015-03-27 Thread Jatin Kala
Thanks Richard, This works, rather obvious now that i think of it! =) On 27/03/2015 4:30 pm, Richard M. Heiberger wrote: just reverse what you did before. newdata <- data newdata[] <- NA newdata[,!apply(is.na(data), 2, any)] <- myfunction(data_no_NA) On Fri, Mar 27, 2015 at 1:13 AM, Jatin Kala

Re: [R] matrix manipulation question

2015-03-27 Thread David Winsemius
On Mar 27, 2015, at 3:41 AM, Stéphane Adamowicz wrote: > Well, it seems to work with me. > No one is doubting that it worked for you in this instance. What Peter D. was criticizing was the construction : complete.cases(t(Y))==T ... and it was on two bases that it is "wrong". The first is tha

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
> >> example. Furthermore in my example no unwanted format occurred. You can > > Yes because data.frame was (luckily) numeric. > Luck has nothing to do with this. I Chose this example on purpose … Stéphane __ R-help@r-project.org mailing list -- To

Re: [R] matrix manipulation question

2015-03-27 Thread PIKAL Petr
Hi > -Original Message- > From: Stéphane Adamowicz [mailto:stephane.adamow...@avignon.inra.fr] > Sent: Friday, March 27, 2015 1:26 PM > To: PIKAL Petr > Cc: peter dalgaard; r-help@r-project.org > Subject: Re: [R] matrix manipulation question > > > Le 27 mars

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Le 27 mars 2015 à 12:34, PIKAL Petr a écrit : > Very, very, very bad solution. > > as.matrix can change silently your data to unwanted format, > complete.cases()==T is silly as Peter already pointed out. > > Perhaps, but it happens that in the original message, the question dealt with a

Re: [R] matrix manipulation question

2015-03-27 Thread PIKAL Petr
: [R] matrix manipulation question Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313 11.5 62

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Well, it seems to work with me. Y <- as.matrix(airquality) head(Y, n=8) Ozone Solar.R Wind Temp Month Day [1,]41 190 7.4 67 5 1 [2,]36 118 8.0 72 5 2 [3,]12 149 12.6 74 5 3 [4,]18 313 11.5 62 5 4 [5,]NA NA 14.3 56

Re: [R] matrix manipulation question

2015-03-27 Thread peter dalgaard
On 27 Mar 2015, at 09:58 , Stéphane Adamowicz wrote: > data_no_NA <- data[, complete.cases(t(data))==T] Ouch! logical == TRUE is bad, logical == T is worse: data[, complete.cases(t(data))] -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 200

Re: [R] matrix manipulation question

2015-03-27 Thread Stéphane Adamowicz
Why not use complete.cases() ? data_no_NA <- data[, complete.cases(t(data))==T] Le 27 mars 2015 à 06:13, Jatin Kala a écrit : > Hi, > I've got a rather large matrix of about 800 rows and 60 columns. > Each column is a time-series 800 long. > > Out of these 60 time series, some have mi

Re: [R] matrix manipulation question

2015-03-26 Thread Richard M. Heiberger
just reverse what you did before. newdata <- data newdata[] <- NA newdata[,!apply(is.na(data), 2, any)] <- myfunction(data_no_NA) On Fri, Mar 27, 2015 at 1:13 AM, Jatin Kala wrote: > Hi, > I've got a rather large matrix of about 800 rows and 60 columns. > Each column is a time-series 800 lon

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Steven Yen
Thank you both. Both John and Peter's suggestions work great!! At 06:17 PM 1/7/2015, John McKown wrote: >On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen ><sye...@gmail.com> wrote: >I like to multiple the first and second column >of a 10 x 3 matrix by 100. The following did no

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
On Wed, Jan 7, 2015 at 3:15 PM, Peter Langfelder wrote: > You can create a suitable matrix bb as below (note the byrow = TRUE argument) > > aa<-matrix(1:30,nrow=10,ncol=3); aa > bb<-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb > dim(aa) > dim(bb) > aa * bb > > > You can also use matrix mu

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread John McKown
On Wed, Jan 7, 2015 at 5:05 PM, Steven Yen wrote: > I like to multiple the first and second column of a 10 x 3 matrix by 100. > The following did not work. I need this in an operation with a much larger > scale. Any help? > > aa<-matrix(1:30,nrow=10,ncol=3); aa > bb<-matrix(c(100,100,1),nrow=1,nc

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
You can create a suitable matrix bb as below (note the byrow = TRUE argument) aa<-matrix(1:30,nrow=10,ncol=3); aa bb<-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb dim(aa) dim(bb) aa * bb You can also use matrix multiplication, but that;s slightly more involved: aa<-matrix(1:30,nrow=10,

Re: [R] matrix

2014-06-30 Thread arun
Hi Izhak, If the position of the elements to be replaced follow the pattern below: seq(1,length(t), by=7) #[1]  1  8 15 t[seq(1,length(t), by=7)] <- c(50,90,100) A.K. On Monday, June 30, 2014 4:19 PM, "Adams, Jean" wrote: t[1, 1] <- 50 t[3, 2] <- 90 t[5, 3] <- 100 Jean On Mon, Jun 30, 20

Re: [R] matrix

2014-06-30 Thread Adams, Jean
t[1, 1] <- 50 t[3, 2] <- 90 t[5, 3] <- 100 Jean On Mon, Jun 30, 2014 at 10:27 AM, IZHAK shabsogh wrote: > > > kindly guide me on how i can delete and replace an element from a matrix t > below > > for example delete first element in column one and replace it with 50, > third element in column

Re: [R] matrix column division by vector

2014-05-14 Thread Jeff Newmiller
Scores well on notational simplicity. Loses big on computational efficiency (lots of terms multiplied with zero, then added to the one nonzero term). --- Jeff NewmillerThe . . Go Liv

Re: [R] matrix column division by vector

2014-05-14 Thread Ted Harding
Maybe I am missing the point -- but what is wrong with line 3 of: m=rbind(c(6,4,2),c(3,2,1)) v= c(3,2,1) m%*%diag(1/v) # [,1] [,2] [,3] # [1,]222 # [2,]111 Ted. On 14-May-2014 15:03:36 Frede Aakmann Tøgersen wrote: > Have a look at ?sweep > > Br. Frede >

Re: [R] matrix column division by vector

2014-05-14 Thread Bert Gunter
psed >>5.040.015.06 >> >> David C >> >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >> Behalf Of Jeff Newmiller >> Sent: Wednesday, May 14, 2014 10:28 AM >> To: carol white; carol white; r-

Re: [R] matrix column division by vector

2014-05-14 Thread Bert Gunter
user system elapsed >5.040.015.06 > > David C > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Jeff Newmiller > Sent: Wednesday, May 14, 2014 10:28 AM > To: carol white; carol white;

  1   2   3   4   5   6   7   >