[R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
Dear R helpers Suppose x  - c(1:3) y  - matrix(1:12, ncol = 3, nrow = 4) y [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Dimitris Rizopoulos
try this: x - 1:3 y - matrix(1:12, ncol = 3, nrow = 4) y * rep(x, each = nrow(y)) I hope it helps. Best, Dimitris On 4/20/2012 10:51 AM, Vincy Pyne wrote: Dear R helpers Suppose x- c(1:3) y- matrix(1:12, ncol = 3, nrow = 4) y [,1] [,2] [,3] [1,]159 [2,]26

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Vincy Pyne
Dear Mr. Dimitris Rizopoulos, Thanks a lot for your great help. It worked nicely. I couldn't have figured it out. Thanks again. Regards Vincy --- On Fri, 4/20/12, Dimitris Rizopoulos d.rizopou...@erasmusmc.nl wrote: From: Dimitris Rizopoulos d.rizopou...@erasmusmc.nl Subject: Re: [R] Matrix

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread David Winsemius
On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote: try this: x - 1:3 y - matrix(1:12, ncol = 3, nrow = 4) y * rep(x, each = nrow(y)) Another way with a function specifically designed for that purpose: sweep(y, 2, x, *) -- David. I hope it helps. Best, Dimitris On

Re: [R] Matrix multiplication by multple constants

2012-04-20 Thread Greg Snow
And another way is to remember properties of matrix multiplication: y %*% diag(x) On Fri, Apr 20, 2012 at 8:35 AM, David Winsemius dwinsem...@comcast.net wrote: On Apr 20, 2012, at 4:57 AM, Dimitris Rizopoulos wrote: try this: x  - 1:3 y  - matrix(1:12, ncol = 3, nrow = 4) y * rep(x,

[R] Matrix problem

2012-04-10 Thread Worik R
Friends I am extracting sub-sets of the rows of a matrix. Generally the result is a matrix. But there is a special case. When the result returned is a single row it is returned as a vector (in the example below an integer vector). If there are 0, or more than 1 rows returned the result is a

Re: [R] Matrix problem

2012-04-10 Thread David Winsemius
On Apr 10, 2012, at 7:33 PM, Worik R wrote: Friends I am extracting sub-sets of the rows of a matrix. Generally the result is a matrix. But there is a special case. When the result returned is a single row it is returned as a vector (in the example below an integer vector). If there

Re: [R] Matrix problem

2012-04-10 Thread Worik R
Thank you. That was exactly what I need. Looking at '?[' I see... drop: For matrices and arrays. If ‘TRUE’ the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. See ‘drop’

Re: [R] Matrix problem

2012-04-10 Thread David Winsemius
On Apr 10, 2012, at 8:01 PM, Worik R wrote: Thank you. That was exactly what I need. Looking at '?[' I see... drop: For matrices and arrays. If ‘TRUE’ the result is coerced to the lowest possible dimension (see the examples). This only works for extracting

[R] matrix with Loop

2012-03-29 Thread Christopher Kelvin
Hello! I got something to ask..whether you can help me with the R program...i got this for example 5x4 matrix..and i want to find:  i) mean for each row of the matrix ii) median for each column of the matrix and i need to do this using a loop function...below is my program..u try to check it for

Re: [R] matrix with Loop

2012-03-29 Thread R. Michael Weylandt
apply(x, 1, mean) apply(x, 2, median) or for more speed rowMeans() ? apply Michael On Thu, Mar 29, 2012 at 9:00 AM, Christopher Kelvin chris_kelvin2...@yahoo.com wrote: Hello! I got something to ask..whether you can help me with the R program...i got this for example 5x4 matrix..and i want

Re: [R] matrix with Loop

2012-03-29 Thread R. Michael Weylandt
Chris Kelvin - Original Message - From: R. Michael Weylandt michael.weyla...@gmail.com To: Christopher Kelvin chris_kelvin2...@yahoo.com Cc: r-help@r-project.org r-help@r-project.org Sent: Thursday, March 29, 2012 11:33 PM Subject: Re: [R] matrix with Loop apply(x, 1, mean) apply(x

Re: [R] matrix(unlist(strsplit())) 'missing value' issue

2012-03-28 Thread MaartenJacobs
Nobody any solution for my problem?? -- View this message in context: http://r.789695.n4.nabble.com/matrix-unlist-strsplit-missing-value-issue-tp4509065p4511668.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org

Re: [R] matrix(unlist(strsplit())) 'missing value' issue

2012-03-28 Thread Petr PIKAL
What problem? Nabble is not available to all and here is not much to cook from. Nobody any solution for my problem?? -- View this message in context: http://r.789695.n4.nabble.com/matrix-unlist- strsplit-missing-value-issue-tp4509065p4511668.html Sent from the R help mailing list

Re: [R] matrix(unlist(strsplit())) 'missing value' issue

2012-03-28 Thread ilai
On Wed, Mar 28, 2012 at 6:49 AM, Petr PIKAL petr.pi...@precheza.cz wrote: What problem? Nabble is not available to all and here is not much to cook from. Indeed. Also the OP actually provided their own solution, just 5 more minutes of googling to find ?sub. bankoffer.3 -

Re: [R] matrix(unlist(strsplit())) 'missing value' issue

2012-03-28 Thread MaartenJacobs
Thank you!! Been googling for hours, but kind of hard to find something if you don't know how to look for it. So thanks again!! Greetings Maarten ilai-2 wrote On Wed, Mar 28, 2012 at 6:49 AM, Petr PIKAL lt;petr.pikal@gt; wrote: What problem? Nabble is not available to all and here is not

[R] matrix(unlist(strsplit())) 'missing value' issue

2012-03-27 Thread MaartenJacobs
*I'm still a R noob, just had a couple of lectures about it in our research master. There is a Deal or no deal experiment where I have to write some code for. Someone wrote a website to gather the data and write it in a .xlsx file. These are seperate files for seperate participants so first I

Re: [R] Matrix Results

2012-03-18 Thread Uwe Ligges
On 13.03.2012 15:40, RMSOPS wrote: Hello Error: could not find function sqldf: Hello, I'm using R Studio, and installed the option of installing the packages sqldbf function. But When I run the code give the next error. install.packages(sqldf) library(RSQLite) require(sqldf) x-

[R] Matrix Results

2012-03-13 Thread RMSOPS
Hello I am developing a small program that to calculate the maximum, minimum and average. The data.frame v is POS DIF 4 - 4 56 4 - 3 61 3 - 3 300 3 - 327 3 - 3 33 3 - 3 87 3 - 4 49 4 - 4 71 4 - 3 121 3 - 4 138 4 - 3 15

Re: [R] Matrix Results

2012-03-13 Thread Petr PIKAL
Hi Hello I am developing a small program that to calculate the maximum, minimum and average. The data.frame v is POS DIF 4 - 4 56 4 - 3 61 3 - 3 300 3 - 327 3 - 3 33 3 - 3 87 3 - 4 49 4 - 4 71 4 - 3 121 3 -

Re: [R] Matrix Results

2012-03-13 Thread jim holtman
Try this: require(sqldf) x - read.fwf(textConnection(4 - 4 56 + 4 - 3 61 + 3 - 3 300 + 3 - 327 + 3 - 3 33 + 3 - 3 87 + 3 - 4 49 + 4 - 4 71 + 4 - 3 121 + 3 - 4 138 + 4 - 3 15), width = c(7,8) , header = FALSE, as.is = TRUE)

[R] Matrix Counts

2012-03-13 Thread RMSOPS
I have next table source destine 33 77 6 6 3 4 4 4 4 3 3 3 3 3 3 3 3 3 3 4 4 4 4 3 3 4 4 3 I'm trying to create an array with the number of occurrences between the source and destination.

Re: [R] Matrix Results

2012-03-13 Thread RMSOPS
Hello is the dataset that was sent to help, has over two columns the source and destination, is the separation of position pos POS DIF SourceDest 4 - 4 56 4 4 4 - 3 61 4 3 3 - 3 300 3 3 3 -

[R] Matrix Another table

2012-03-13 Thread RMSOPS
I have next table source destine 3 3 7 7 6 6 3 4 4 4 4 3 3 3 3 3 3 3 3 3 3 4 4 4 4 3 3 4 4 3 I'm trying to create an array with the number of occurrences between the source and destination. id_ap-levels(factor(df$v_source)) num_AP-length(levels(factor(df$v_source)))

Re: [R] Matrix Another table

2012-03-13 Thread Sarah Goslee
Hi, On Tue, Mar 13, 2012 at 7:51 AM, RMSOPS ricardosousa2...@clix.pt wrote: I have next table source destine 3 3 7 7 6 6 3 4  4 4  4 3 3 3 3 3  3 3  3 3 3 4  4 4  4 3  3 4  4 3 It is so much easier if you use dput to provide reproducible data, as the posting guide asks. There's

Re: [R] Matrix Results

2012-03-13 Thread RMSOPS
Hello Error: could not find function sqldf: Hello, I'm using R Studio, and installed the option of installing the packages sqldbf function. But When I run the code give the next error. install.packages(sqldf) library(RSQLite) require(sqldf) x - read.fwf(textConnection(4 - 4 56 + 4

Re: [R] Matrix Another table

2012-03-13 Thread RMSOPS
Hello, this solve my problem. table(testdata$source, testdata$destine) Thanks -- View this message in context: http://r.789695.n4.nabble.com/Re-Matrix-Another-table-tp4469376p4469384.html Sent from the R help mailing list archive at Nabble.com.

[R] Matrix negative fraction power

2012-03-11 Thread Ebrahim Jahanshiri
Dear list, I understand that to raise matrix A to power (-1/2) we should use something like this: eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors) [from previous discussions: http://r.789695.n4.nabble.com/matrix-power-td900335.html] But this will only do it for negative

Re: [R] Matrix negative fraction power

2012-03-11 Thread Peter Langfelder
On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri e.jahansh...@gmail.com wrote: Dear list, I understand that to raise matrix A to power (-1/2) we should use something like this: eigen(A)$vectors%*%diag(1/sqrt(eigen(A)$values))%*%t(eigen(A)$vectors) [from previous discussions:

Re: [R] Matrix negative fraction power

2012-03-11 Thread Joshua Wiley
On Sun, Mar 11, 2012 at 8:56 AM, Peter Langfelder peter.langfel...@gmail.com wrote: On Sun, Mar 11, 2012 at 1:46 AM, Ebrahim Jahanshiri e.jahansh...@gmail.com wrote: Dear list, I understand that to raise matrix A to power (-1/2) we should use something like this:

Re: [R] Matrix negative fraction power

2012-03-11 Thread Spencer Graves
If my memory is correct, the archives of this list contains several discussions of round off error problems associated with different methods for computing things like this. The Matrix package (part of the base distribution) contains a function expm, whose help file says, The expm

Re: [R] Matrix negative fraction power

2012-03-11 Thread Berend Hasselman
On 11-03-2012, at 17:52, Spencer Graves wrote: If my memory is correct, the archives of this list contains several discussions of round off error problems associated with different methods for computing things like this. The Matrix package (part of the base distribution) contains a

Re: [R] Matrix negative fraction power

2012-03-11 Thread Berend Hasselman
On 11-03-2012, at 18:18, Berend Hasselman wrote: On 11-03-2012, at 17:52, Spencer Graves wrote: If my memory is correct, the archives of this list contains several discussions of round off error problems associated with different methods for computing things like this. The Matrix

[R] Matrix Package, sparseMatrix, more NaN's than zeros

2012-03-04 Thread Ben quant
Hello, I have a lot of data and it has a lot of NaN values. I want to compress the data so I don't have memory issues later. Using the Matrix package, sparseMatrix function, and some fiddling around, I have successfully reduced the 'size' of my data (as measured by object.size()). However, NaN

Re: [R] Matrix problem to extract animal associations

2012-02-27 Thread ilai
set.seed(1) (DFid - data.frame( x = sample(1:20,10), y = sample(1:20,10), IDs = sapply(1:10,function(i) paste(ID,i,sep= require(spdep) coordinates(DFid) - ~x+y coords - coordinates(DFid) dnn4 - dnearneigh(DFid,0,4) summary(dnn4) plot(DFid) plot(dnn4,coords,add=T,col=2) nb2mat(dnn4,

[R] Matrix problem to extract animal associations

2012-02-26 Thread Ross Dwyer
Dear List, I have been trying to extract associations from a matrix whereby individual locations are within a certain distance threshold from one another. I have been able to extract those individuals where there is 'no interaction' (i.e. where these individuals are not within a specified

[R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread John Sorkin
I am trying to use matrix algebra to get the beta coefficients from a simple bivariate linear regression, y=f(x). The coefficients should be computable using the following matrix algebra: t(X)Y / t(x)X I have pasted the code I wrote below. I clearly odes not work both because it returns a

Re: [R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread Mark Leeds
Hi John: I don't understand what you're doing ( not saying that it's wrong. I just don't follow it ). Below is code for computing the coefficients using the matrix way I follow. Others may understand what you're doing and be able to fix it so I wouldn't just use below immediately. xprimex -

Re: [R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread John Sorkin
Mark Thank you! John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please

Re: [R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread Berend Hasselman
On 18-02-2012, at 14:36, John Sorkin wrote: I am trying to use matrix algebra to get the beta coefficients from a simple bivariate linear regression, y=f(x). The coefficients should be computable using the following matrix algebra: t(X)Y / t(x)X I have pasted the code I wrote below. I

Re: [R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread John Sorkin
Thank you, John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call

Re: [R] Matrix algebra in R to compute coefficients of a linear regression.

2012-02-18 Thread Frank Harrell
The Wilcoxon test is not related to the difference in medians but rather to the Hodges-Lehmann estimator, which is the median of all possible differences of observations between sample 1 and sample 2. So what's needed is a confidence interval for this estimate, obtainable from inverting the

[R] matrix subsetting

2012-02-13 Thread Sam Steingold
if I have a vector, I can find the indexes which satisfy a condition: x - rnorm(10) [1] 0.4751132 -0.5442322 -0.1979854 -0.2455521 0.8349336 -0.4283345 [7] 0.6108130 2.0576160 1.1251716 -1.3933637 x[x0] [1] 0.4751132 0.8349336 0.6108130 2.0576160 1.1251716 (1:10)[x0] [1] 1 5 7 8 9 how

Re: [R] matrix subsetting

2012-02-13 Thread R. Michael Weylandt michael.weyla...@gmail.com
which(x0) or which(x0, arr.ind=TRUE) depending on your application. Michael On Feb 13, 2012, at 5:38 PM, Sam Steingold s...@gnu.org wrote: if I have a vector, I can find the indexes which satisfy a condition: x - rnorm(10) [1] 0.4751132 -0.5442322 -0.1979854 -0.2455521 0.8349336

Re: [R] matrix subsetting

2012-02-13 Thread Duncan Murdoch
On 12-02-13 5:46 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: which(x0) or which(x0, arr.ind=TRUE) depending on your application. Or even x0 if you want a matrix of TRUE/FALSE values. You can use x[x0] to get the values, but they won't be in matrix form. Duncan Murdoch

[R] matrix element position: from length to dim

2012-02-02 Thread Ana
How can I pass from position in length inside a matrix to position in dim ? a=matrix(c(1:999),nrow=9) which(a==87)#position in length 1:length(a) 87 which(a==87,arr.ind=TRUE) #position in dim row col [1,] 6 10 __ R-help@r-project.org

Re: [R] matrix element position: from length to dim

2012-02-02 Thread Petr Savicky
On Thu, Feb 02, 2012 at 02:08:37PM +0100, Ana wrote: How can I pass from position in length inside a matrix to position in dim ? a=matrix(c(1:999),nrow=9) which(a==87)#position in length 1:length(a) 87 which(a==87,arr.ind=TRUE) #position in dim row col [1,] 6 10 Hi.

Re: [R] matrix element position: from length to dim

2012-02-02 Thread R. Michael Weylandt
Also take a look at the arrayInd() function which is what's used by which() internally for the arr.ind = TRUE case. Michael On Thu, Feb 2, 2012 at 8:25 AM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, Feb 02, 2012 at 02:08:37PM +0100, Ana wrote: How can I pass from position in length inside a

[R] Matrix and boucle.

2012-01-24 Thread Glen360
Hello, I made a boucle that put data inside N matrix. So for N=45, I have M1:M45. Then I want to make a sn.em on each columns of each matrix. I don't know how to call a i matrix (matrix(i) / matrix[i]) for i in 1:45. Here is the code to make M1:M45 numberOfConfig8min -

Re: [R] matrix position to list of coordinates

2012-01-02 Thread Willi Richert
Hi Ana, d=dim(A) d [1] 2 4 cbind(rep(1:d[1], each=d[2]), rep(1:d[2], d[1])) [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]14 [5,]21 [6,]22 [7,]23 [8,]24 Thanks, wr * Ana rrast...@gmail.com [2012-01-01 23:21:12 +0100]: How can I

Re: [R] matrix position to list of coordinates

2012-01-02 Thread Willi Richert
Hi Ana, most probably this is one of the more ugly solutions: d=dim(A) d [1] 2 4 cbind(rep(1:d[1], each=d[2]), rep(1:d[2], d[1])) [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]14 [5,]21 [6,]22 [7,]23 [8,]24 Thanks, wr * Ana

[R] matrix position to list of coordinates

2012-01-01 Thread Ana
How can I extract a list of the positions in the matrix? A=matrix(1:8, nrow=2,ncol=4) A [,1] [,2] [,3] [,4] [1,]1357 [2,]2468 Something like this pos.A 1 1 1 2 1 3 1 4 2 1 2 2 2 3 2 4 __ R-help@r-project.org

Re: [R] matrix position to list of coordinates

2012-01-01 Thread Sarah Goslee
Here's one way: data.frame(rowID=as.vector(row(A)), colID=as.vector(col(A)), A=as.vector(A)) rowID colID A 1 1 1 1 2 2 1 2 3 1 2 3 4 2 2 4 5 1 3 5 6 2 3 6 7 1 4 7 8 2 4 8 You can sort that as desired. Sarah On Sun, Jan 1, 2012

Re: [R] matrix position to list of coordinates

2012-01-01 Thread Willi Richert
Hi Ana, most probably this is one of the more ugly solutions: d=dim(A) d [1] 2 4 cbind(rep(1:d[1], each=d[2]), rep(1:d[2], d[1])) [,1] [,2] [1,]11 [2,]12 [3,]13 [4,]14 [5,]21 [6,]22 [7,]23 [8,]24 Thanks, wr * Ana

[R] matrix multivariate bootstrap: order of results in $t component

2011-12-21 Thread Michael Friendly
[This question is hopefully straight-forward, but difficult to provide reproducible code.] I'm doing a multivariate bootstrap, using boot::boot(), where the output of the basic computation is a k x p matrix of coefficients, representing a tuning constant x variable, as shown in the $t0

Re: [R] matrix multivariate bootstrap: order of results in $t component

2011-12-21 Thread John Fox
- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Michael Friendly Sent: December-21-11 2:17 PM To: R-help Subject: [R] matrix multivariate bootstrap: order of results in $t component [This question is hopefully straight-forward, but difficult

Re: [R] matrix calculation

2011-12-10 Thread R. Michael Weylandt
Perhaps something like this (untested) -- it's going to depend on the exact structure of your data so if this doesn't work, please use dput() to send a plain text representation: tapply(data, data$animal, function(d) d[, c(A01, A02)] - d[d$time == d0, c(A01, A02)] ) In short, take data split it

Re: [R] matrix calculation

2011-12-10 Thread David Winsemius
On Dec 10, 2011, at 9:13 AM, R. Michael Weylandt wrote: Perhaps something like this (untested) -- it's going to depend on the exact structure of your data so if this doesn't work, please use dput() to send a plain text representation: tapply(data, data$animal, function(d) d[, c(A01, A02)] -

[R] matrix calculation

2011-12-09 Thread Junyu Lee
Hello, I have a matrix animaltime A01 A02 A d0 -5.4 2.7 A d1124.6 5.9 A d224 3.96.3 B

[R] Matrix for correlation

2011-11-29 Thread Geophagus
hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE Car 23 Train26 Plane 25 Cab

Re: [R] Matrix for correlation

2011-11-29 Thread R. Michael Weylandt
I'm not sure how you mean to calculate correlation if you have a single observation of each mediumcan you provide your data (or a subset thereof) so we can see what you are actually working with and if correlation makes sense. Michael On Tue, Nov 29, 2011 at 10:41 AM, Geophagus

Re: [R] Matrix for correlation

2011-11-29 Thread Uwe Ligges
On 29.11.2011 16:41, Geophagus wrote: hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value in a column. Maybe like corr(x, method = xyz). My x has two columns maybe like this: MEDIA VALUE

Re: [R] Matrix for correlation

2011-11-29 Thread Grant McDonald
...@twain-systems.com CC: r-help@r-project.org Subject: Re: [R] Matrix for correlation On 29.11.2011 16:41, Geophagus wrote: hi @ all, I have problem with creating a matrix for a cor() function. I try to use the cor() function on a matrix to test the correlation between each value

Re: [R] Matrix for correlation

2011-11-29 Thread Geophagus
Hi Michael, thank you so much for your fast reply. On the image below there is an example of what I mean. I need the correlation between the values on the fields with ?. http://r.789695.n4.nabble.com/file/n4119734/corr_ex.png But my source data is not in a matrix. It looks like the table in

Re: [R] Matrix for correlation

2011-11-29 Thread R. Michael Weylandt
I think everyone is worried about your data, not what a correlation matrix is. Now I think you may be even more turned around: you want a correlation between the values of the correlation matrix? Just dput() your data object and copy it into your email and we'll see if it's possible to calculate

Re: [R] Matrix for correlation

2011-11-29 Thread Geophagus
Hi @ all and sorry for the confusion, my problem is solved. I also know a corellation is - it was only a formatting and describing problem. Grant gave me the right advice with the kruskal-wallis! Thanks GeOphagus -- View this message in context:

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

2011-11-06 Thread David Winsemius
On Nov 6, 2011, at 12:21 AM, R. Michael Weylandt wrote: There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really

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

2011-11-06 Thread R. Michael Weylandt michael.weyla...@gmail.com
It looks like pdf is not a scalar (that term actually has no meaning in R but I know what you mean) but is rather a 1x1 matrix, as attested by the fact it has dimensions. If you give dnorm() a matrix it will return one, as it did here. Perhaps you should look at the is.matrix() and

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

2011-11-06 Thread Joshua Wiley
Hi, R may not have a special scalar, but it is common, if informal, in linear algebra to refer to a 1 x 1 matrix as a scalar. Indeed, something like: 1:10 * matrix(2) or matrix(2) * 1:10 are both valid. Even matrix(2) %*% 1:10 and 1:10 %*% matrix(2) work, where the vector seems to be

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

2011-11-06 Thread Steven Yen
Mucha gracias!! as.vector worked like a charm and, in this case, produced the same results as c(): c(pdf)*v as.vector(pdf)*v At 07:02 PM 11/6/2011, R. Michael Weylandt michael.weyla...@gmail.com wrote: It looks like pdf is not a scalar (that term actually has no meaning in R but I

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

2011-11-05 Thread R. Michael Weylandt
There are a few (nasty?) side-effects to c(), one of which is stripping a matrix of its dimensionality. E.g., x - matrix(1:4, 2) c(x) [1] 1 2 3 4 So that's probably what happened to you. R has a somewhat odd feature of not really considering a pure vector as a column or row vector but being

[R] Matrix element-by-element multiplication

2011-11-04 Thread Steven Yen
is there a way to do element-by-element multiplication as in Gauss and MATLAB, as shown below? Thanks. --- a 1.000 2.000 3.000 x 1.0002.0003.000 2.0004.0006.000 3.000

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

2011-11-04 Thread R. Michael Weylandt
Did you even try? a - 1:3 x - matrix(c(1,2,3,2,4,6,3,6,9),3) a*x [,1] [,2] [,3] [1,]123 [2,]48 12 [3,]9 18 27 Michael On Fri, Nov 4, 2011 at 7:26 PM, Steven Yen s...@utk.edu wrote: is there a way to do element-by-element multiplication as in Gauss and

[R] Matrix Approx

2011-10-20 Thread onewastedlife
Need help with finding out approx over each row of a matrix. Here is the setup: years - matrix(c(1,2,3,1,2,3),nrow=2, ncol=3,byrow=TRUE) rates - matrix(c(1,2,3,11,12,13), nrow = 2, ncol=3, byrow=TRUE) points - matrix(c(1.5, 1.5), nrow=2, ncol=1, byrow=TRUE) so basically i have above three

Re: [R] matrix multiplication

2011-10-11 Thread B77S
Your question as answered by Timothy in your previous thread http://r.789695.n4.nabble.com/Re-Creating-the-mean-using-algebra-matrix-td3895689.html flokke wrote: Dear all, Sorry to bother you with such a stupid question, but I just cannot find the solution to my problem. I'd like to

[R] matrix multiplication

2011-10-11 Thread flokke
Dear all, Sorry to bother you with such a stupid question, but I just cannot find the solution to my problem. I'd like to use matrix multiplication for meanA and factorial 3. I use the command meanA%*%factorial 3. But everything I get is: Error in factorial3 %*% A : non-conformable arguments

Re: [R] matrix multiplication

2011-10-11 Thread Rolf Turner
On 12/10/11 09:11, flokke wrote: Dear all, Sorry to bother you with such a stupid question, but I just cannot find the solution to my problem. I'd like to use matrix multiplication for meanA and factorial 3. I use the command meanA%*%factorial 3. But everything I get is: Error in factorial3 %*%

Re: [R] Matrix/Vector manipulation

2011-10-04 Thread fernando.cabrera
the 1*1.3 part because 3+2 4 [1] 3.6 Cheers, Fer -Original Message- From: David Reiner [mailto:david.rei...@xrtrading.com] Sent: 3. oktober 2011 17:57 To: Cabrera, Fernando Álvarez; r-help@r-project.org Subject: RE: [R] Matrix/Vector manipulation sum(ifelse(cumsum(W)=v, W, 0) * R) HTH

Re: [R] Matrix/Vector manipulation

2011-10-04 Thread fernando.cabrera
(W) = 4, W, 0) * R) # ignores the 1*1.3 part because 3+2 4 [1] 3.6 Cheers, Fer -Original Message- From: David Reiner [mailto:david.rei...@xrtrading.com] Sent: 3. oktober 2011 17:57 To: Cabrera, Fernando Álvarez; r-help@r-project.org Subject: RE: [R] Matrix/Vector manipulation sum(ifelse

[R] matrix of chi-square results for all combinations of data frame

2011-10-04 Thread christiaan pauw
Hi everybody I have a questionnaire with a lot of questions that allow for more than one option to be chosen (like a tickbox in a html form). The data captured on a mobile device and is supplied in a format where every option is a separate variable (logical). I want to develop a generic function

[R] Matrix/Vector manipulation

2011-10-03 Thread fernando.cabrera
Hi guys, Have the following problem computing vectors with pure vector algebra and end up reverting to recursion or for-looping. Function my_cumsum calculates a weighted average (W) of ratios (R), but only up to the given size/volume (v). Now I recurse into the vector (from left to right)

Re: [R] Matrix/Vector manipulation

2011-10-03 Thread David Reiner
sum(ifelse(cumsum(W)=v, W, 0) * R) HTH, David L. Reiner -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of fernando.cabr...@nordea.com Sent: Monday, October 03, 2011 9:50 AM To: r-help@r-project.org Subject: [SPAM] - [R] Matrix

Re: [R] Matrix and list indices

2011-09-28 Thread fernando.cabrera
Thanks Michael it works! Have to say it is amazing what you can do in R with a few lines (a line in this case) of code. Fernando From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: 27. september 2011 15:43 To: Cabrera, Fernando Álvarez Subject: Re: [R] Matrix and list indices

[R] Matrix and list indices

2011-09-27 Thread fernando.cabrera
Hi guys, I am trying to replace all elements of earth that are equal to zero with their corresponding elements in mars. I can do the replace with a bunch of for-loops, but I don't think this is the R way of doing things. my_list - list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)),

Re: [R] Matrix and list indices

2011-09-27 Thread R. Michael Weylandt
On Tue, Sep 27, 2011 at 9:43 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Untested, I believe this should work, though you might need to modify for floating point funny business in testing the equalities: my_list - list( earth=array(c(0,0,45,0,0,45,0,45),dim=c(2,2,2)),

[R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Xavier Fernández i Marín
Dear all, When trying to multiply the same matrices repeatedly I get different results some of the times. It is not systematic, which is the fact that is giving me more trouble to try to isolate the problem. Basically I am doing X %*% B, where X is a Nx2 matrix and B is a vector with 2 values.

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Joshua Wiley
I cannot replicate this on, even with 1 milllion reps on: R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) or R Under development (unstable) (2011-08-13 r56733) Platform: x86_64-pc-mingw32/x64 (64-bit) Perhaps it is OS dependent (I am away from my linux box at the moment)?

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Xavier Fernández i Marín
Joshua Wiley vas escriure el dia dt, 13 set 2011: I cannot replicate this on, even with 1 milllion reps on: R version 2.13.1 (2011-07-08) Platform: i386-pc-mingw32/i386 (32-bit) or R Under development (unstable) (2011-08-13 r56733) Platform: x86_64-pc-mingw32/x64 (64-bit) Perhaps

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Rolf Turner
I tried your example code on my laptop running Ubuntu Linux, and of course it ran --- just as it should (*has* to!) without any problem; no errors thrown. This sort of thing should not/does not/cannot happen under ``normal circumstances''. There has to be something wrong somewhere in your

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Xavier Fernández i Marín
Rolf Turner vas escriure el dia dt, 13 set 2011: I tried your example code on my laptop running Ubuntu Linux, and of course it ran --- just as it should (*has* to!) without any problem; no errors thrown. This sort of thing should not/does not/cannot happen under ``normal circumstances''.

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Ben Bolker
Xavier Fernández i Marín xfim.ll at gmail.com writes: Rolf Turner vas escriure el dia dt, 13 set 2011: [snip] This sort of thing should not/does not/cannot happen under ``normal circumstances''. There has to be something wrong somewhere in your setup. Either your hardware or your

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Ben Bolker
Xavier Fernández i Marín xfim.ll at gmail.com writes: More elements: In python the same algorithm does not show this strange behaviour. Is Python using the same BLAS/LAPACK? __ R-help@r-project.org mailing list

Re: [R] Matrix multiplication gives different results some of the times (NaN)

2011-09-13 Thread Xavier Fernández i Marín
Ben Bolker vas escriure el dia dt, 13 set 2011: You mentioned that you had compiled R yourself. Can you replicate this with a stock R binary, i.e. from a Red Hat or Ubuntu repository? If not, can you give details of your compilation setup, especially if you are using a specialized or

Re: [R] matrix into vector with vertex names

2011-08-24 Thread joe j
Hi Gabor, Thanks. I will try to figure out the solution you suggest. I found out about melt() from a discussion forum; it seems to me that melt()$value is similar to c(), and when I modified the script as below it 'seems' to be running faster. Anyway in the end I only needed to use a smaller

[R] Matrix:::qr.qy and signature(qr = sparseQR, y = dgCMatrix)

2011-08-23 Thread Felix Lamp
sessionInfo() R version 2.13.1 (2011-07-08) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1]

Re: [R] matrix indexing (igraph ?)

2011-08-18 Thread Gábor Csárdi
This is not an igraph issue, I believe. You need to go over your indices and update the matrix, i.e. for (i in seq_along(t.list)) { temp[t.list[i], c.list[i]] - temp[t.list[i], c.list[i]] + 1 } Best, Gabor On Tue, Aug 2, 2011 at 4:50 PM, Robinson, David G dro...@sandia.gov wrote: I realize

Re: [R] matrix into vector with vertex names

2011-08-18 Thread Gábor Csárdi
Joe, what is melt() supposed to do here? What's wrong with the simple solution of creating a data.frame first, and then filling it with values through a loop? Actually, keeping the matrix is just as good, indexing is just as fast, and takes the same amount of memory as your three column matrix,

[R] matrix correlations with different packages

2011-08-11 Thread Bókony Veronika
Dear all, I'm calculating matrix correlations with permutation tests and I got this funny result. All correlation coefficients are the same with mantel.test {ncf} and pcol {simba} but the two functions yield dramatically different p-values (using the same number of permutations). Could

Re: [R] matrix correlations with different packages

2011-08-11 Thread Jari Oksanen
Dear Veronika, I'm calculating matrix correlations with permutation tests and I got this funny result. All correlation coefficients are the same with mantel.test {ncf} and pcol {simba} but the two functions yield dramatically different p-values (using the same number of permutations). Could

[R] matrix into vector with vertex names

2011-08-05 Thread joe j
Using Igraph, I create shortest paths, then convert the matrix into three column vectors - vertex1, vertex2, shortestpath - as the code below shows. #code for generating shortest path matrix and creating a 3 columns from an igraph graph object y y_s-shortest.paths(y, weights = NULL) y_s -

<    1   2   3   4   5   6   7   8   9   10   >