[R] fill up a matrix

Gabor Grothendieck ggrothendieck at myway.com
Thu Apr 22 14:45:05 CEST 2004


Try this:

m <- matrix(1:9, 3)
m[-1,] <- matrix(11:16,2)


Luis Rideau Cruz <Luisr <at> frs.fo> writes:

: 
: Hi all,
: 
: I want to fill in this matrix vectors (by column) without overwriting the 
first elements in column 1995.
: 
: Is there any other way than concatenate the first element with the vector 
and then assign this new vector 
: to the column in matrix?   
: 
:  matrix[,"3"]<-c(1591,"vector")
:  matrix[,"4"]<-c(405,"vector")
: ...
: ...
: 
:                                matrix
:              2     3     4      5     6   7    8    9   10
: 1995  278 1591 405 482 285 99 220 48  4
: 1996 1220   NA  NA  NA  NA NA  NA NA NA
: 1997 3106   NA  NA  NA  NA NA  NA NA NA
: 1998 1895   NA  NA  NA  NA NA  NA NA NA
: 1999 1376   NA  NA  NA  NA NA  NA NA NA
: 2000  565   NA  NA  NA  NA NA  NA NA NA
: 2001  491   NA  NA  NA  NA NA  NA NA NA
: 2002 1169   NA  NA  NA  NA NA  NA NA NA
: 2003 2310   NA  NA  NA  NA NA  NA NA NA
: 
: 
: Luis Ridao Cruz
: FiskirannsÃ³knarstovan
: NÃ³atÃºn 1
: P.O. Box 3051
: FR-110 TÃ³rshavn
: Faroe Islands
: Phone:             +298 353900
: Phone(direct): +298 353912
: Mobile:             +298 580800
: Fax:                 +298 353901
: E-mail:              luisr <at> frs.fo
: Web:                www.frs.fo
: 
: ______________________________________________
: R-help <at> stat.math.ethz.ch mailing list
: https://www.stat.math.ethz.ch/mailman/listinfo/r-help
: PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
: 
:




More information about the R-help mailing list