[R] filling columns in frame according to another column frame
Luis Ridao Cruz
Luisr at frs.fo
Wed Feb 23 15:14:51 CET 2005
R-help,
I have a frame which I want to fill up conditioning to another data
frame column.
The one I want to fill up is as follows (basically an empty one):
> test2
cm 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9
The other looks like :
> test1
cm 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
38 0 0 1 0 0 0 6 0 0 0 0 0 0 0 0 0
39 0 0 1 0 0 0 0 0 0 0 0 0 6 0 0 0
40 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
41 0 0 2 0 0 0 0 0 0 0 6 0 0 0 0 0
43 0 0 1 0 0 0 4 0 0 0 0 0 0 0 0 0
44 0 0 4 0 0 0 5 0 0 0 0 0 0 0 0 0
45 0 0 2 0 0 0 0 0 0 0 6 0 0 0 0 0
47 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0
48 0 0 2 0 0 0 0 0 0 6 0 0 0 0 0 0
49 0 0 2 0 0 0 0 0 0 6 0 0 0 0 0 0
50 0 0 3 0 0 0 0 0 0 3 0 0 0 0 0 0
51 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 0
Length of both frames are different ( test2 = 150 and test1 = 70 )
The key column is 'cm'
I have tried someting (fill column '3' in test2):
test2 [, '3' ]<-
ifelse ( test2$'cm' %in% test1$'cm' , test1$'3' , 0)
but the result is wrong.
Any suggestions?
Thanks in advance
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 2
minor 0.1
year 2004
month 11
day 15
language R
More information about the R-help
mailing list