[R] Matrix Help

Mark Knecht markknecht at gmail.com
Mon Feb 21 00:12:51 CET 2011


On Sun, Feb 20, 2011 at 2:56 PM, Dmitry Berman <ravenblur at gmail.com> wrote:
> On Sun, Feb 20, 2011 at 5:55 PM, Dmitry Berman <ravenblur at gmail.com> wrote:
>
>> Listers,
>>
>> I have a simple matrix:
>>
>> ----------------------------------
>> m <-c(1:7)
>> m <- cbind(m)
>>
>> m
>> [1,] 1
>> [2,] 2
>> [3,] 3
>> [4,] 4
>> [5,] 5
>> [6,] 6
>> [7,] 7
>> -----------------------------------
>>
>> I want to add a second column using:
>>
>>
>>
> m[,2] <- cbind(m,8:14)
> But I get the error:
> Error in m[, 2] <- cbind(m, 8:14) : subscript out of bounds
>
> What am I doing wrong?
>
> Thanks
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

How about:

m1 <-c(1:7)
M1<-cbind(m1)
M1

m2 <-c(2:8)
M2<-cbind(m2)
M2

cbind(M1,M2)



More information about the R-help mailing list