From: Piet van Remortel <piet.vanremortel_at_gmail.com>

Date: Wed 30 Mar 2005 - 06:47:02 EST

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 Wed Mar 30 06:56:07 2005

Date: Wed 30 Mar 2005 - 06:47:02 EST

I have a re-occuring typical problem that I don't know how to solve efficiently.

an example for a single dataset:

#all identifiers

> rep <- c(10:20)

#Identifiers in my dataset (a subset of rep)

> rep1 <- c(12,13,15,16,17,18)

#measurements in this dataset

> rep1.r <- c(112,113,115,116,117,118)

#the IDs and values of my dataset together

> data <- cbind(rep1, rep1.r)

[1,] 12 112 [2,] 13 113 [3,] 15 115 [4,] 16 116 [5,] 17 117 [6,] 18 118

Now, I want to put the values 112, 113, 115,... in the correct rows of the final table, using the identifiers as an indicator of which row to put it in, so that I finally obtain:

rep res

10 NA

11 NA

12 112

13 113

14 NA

15 115

16 116

17 117

18 118

19 NA

20 NA

I try to avoid repeating 'which' a lot and filling in every identifier's observation etc, since I will be doing this for thousands of rows at once. There must be an efficient way using factors, tapply etc, but I have trouble finding it. Ideal would be if this could be done in one go, instead of looping.

Any suggestions ?

Thanks,

Piet

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 Wed Mar 30 06:56:07 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:30:57 EST
*