Re: [R] Simple question on replace a matrix row

2010-02-01 Thread anna
Hello guys, I wanted to thank you, each one of you led me step by step to the core of the problem. The matrix I was working on was made of rows obtained each one by the lapply function. So by using lapply I was getting a matrix which rows were not numeric vectors but lists. To solve this I used a

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
On Jan 29, 2010, at 6:53 PM, anna wrote: Well I just tried to convert it with data.frame and then data.matrix and it returned me a numeric vector but I am not done yet, let's see if it works, if it doesn't I will try sapply. I think I didn't use sapply because the vectors I am using in

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
Well I just tried to convert it with data.frame and then data.matrix and it returned me a numeric vector but I am not done yet, let's see if it works, if it doesn't I will try sapply. I think I didn't use sapply because the vectors I am using in lapply are of different lengths. - Anna Lippel

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
On Jan 29, 2010, at 6:14 PM, anna wrote: Bill this is exactly what is happening, by using lapply I am having a list and not a numeric vector, I want a numeric vector, is there a way to convert that list to a numeric vector? You could see if substituting sapply would yield a matrix. It w

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
Bill this is exactly what is happening, by using lapply I am having a list and not a numeric vector, I want a numeric vector, is there a way to convert that list to a numeric vector? - Anna Lippel -- View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
Dennis, as soon as I do : > mat3[1, ] <- mat1 and class(mat3) I get a list and not a matrix anymore...So yes you drove me to the problem, mat1 is not one-row numeric matrix but a list. - Anna Lippel -- View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
David, I think I am going close to the problem, at the end of the function ComputeSignalReturns I build the matrix summary with cbind. So when I make class(summary) I get "matrix" but when I make class(summary[1,]) I get "list" Excuse me if I didn't show the problem the right way, I am still new a

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread William Dunlap
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of anna > Sent: Friday, January 29, 2010 2:46 PM > To: r-help@r-project.org > Subject: Re: [R] Simple q

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
On Jan 29, 2010, at 4:54 PM, anna wrote: I was trying to avoid the code because I wanted to simplify it but here we go: mat2<- matrix(nrow = 30, ncol = 7) colnames(mat2) <-c( "A", "B", "C", "D", "E", "F", "G") mat1<-mainMat[1,] I get mainMat[1,] from the following function: Comput

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
What I did now is that I checked the class of both matrix before assigning the first row of mat2: class(mainMat) --> "matrix" class(mainMat[1,]) --> "list" class(mat2) --> "matrix" mat2[1,]<-mainMat[1,] class(mat2) --> "list" I think the problem comes from mainMat[1,] that should be of class "mat

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
I was trying to avoid the code because I wanted to simplify it but here we go: mat2<- matrix(nrow = 30, ncol = 7) colnames(mat2) <-c( "A", "B", "C", "D", "E", "F", "G") mat1<-mainMat[1,] I get mainMat[1,] from the following function: ComputeSignalReturns <- function(vec1

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread Dennis Murphy
Hi: Check the class and dimensions of your objects. If mat1 is either an eight element numeric vector or a one-row matrix, you should have no problem: > mat1 <- 1:8 # vector > mat2 <- matrix(rnorm(240), nrow =30) > class(mat1) [1] "integer" > class(mat2) [1] "matrix" > mat3 <- mat2 > mat3

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
On Jan 29, 2010, at 4:33 PM, anna wrote: Here is how I get mat1: I have a matrix mainMat of 4 rows and 8 columns, I take the first row of it to build mat1. The problem might come from how I build mainMat --> each column comes from an lapply function which returns a list but I convert i

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
Here is how I get mat1: I have a matrix mainMat of 4 rows and 8 columns, I take the first row of it to build mat1. The problem might come from how I build mainMat --> each column comes from an lapply function which returns a list but I convert it to a matrix [4,1]... - Anna Lippel -- View t

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
I convert them both before making matrix() on them. Let me try to send you more details - Anna Lippel -- View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1430130.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
On Jan 29, 2010, at 3:55 PM, anna wrote: Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to replace the first row of mat2 with mat1, this is what I do: mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want it to stay a matrix... What makes yo

[R] Simple question on replace a matrix row

2010-01-29 Thread anna
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to replace the first row of mat2 with mat1, this is what I do: mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want it to stay a matrix... - Anna Lippel -- View this message in context: http://n4.na