[R] Attributing values to matrix according to names

From: Schneider, Manuel <Manuel.Schneider_at_eawag.ch>
Date: Fri 21 Oct 2005 - 00:01:19 EST


Dear R-helpers

Apologies for the basic question, but I just got stuck:

I would like to write values from a vector into array cells with the same names

> count[1:10]

10010 10014 10015 10017 10030 10080 10100 10230 10250 10280

    0 0 0 0 0 1 1 0 2 0

>data[1:10,,1]

      [,1] [,2] [,3] [,4] [,5]
10010 NA NA NA NA NA
10014 NA NA NA NA NA
10015 NA NA NA NA NA
10016 NA NA NA NA NA
10017 NA NA NA NA NA
10100 NA NA NA NA NA
10140 NA NA NA NA NA
10150 NA NA NA NA NA
10160 NA NA NA NA NA
10170 NA NA NA NA NA

> length(count)

[1] 2842

> dim(data)

[1] 4667 5 10

My operation should result in

>data[1:10,,1]

      [,1] [,2] [,3] [,4] [,5]
10010 0 NA NA NA NA
10014 0 NA NA NA NA
10015 0 NA NA NA NA
10016 NA NA NA NA NA
10017 0 NA NA NA NA
10100 1 NA NA NA NA
10140 NA NA NA NA NA
10150 NA NA NA NA NA
10160 NA NA NA NA NA
10170 NA NA NA NA NA

> data["10014",1,1]<-count["10014"]

works but

> data["names(count)",1,1]<-count["names(count)"]
Fails with Error: indexing outside limits.

Many thanks for any help

Manuel



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Oct 21 00:33:32 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:46 EST