Skip to content
Prev 86082 / 398526 Next

adding variable into dataframe by indice

Hi

not sure if I understand correctly but table() can be used

ttt <- table(asubs112$fir)
prop <- ttt/nrow(asubs112)
asubs112$prop <-
prop[match(asubs112$first_drink,as.numeric(names(prop)))]
IND_ID rs1042364 first_drink      prop
2      11     (1,2)           7 0.3333333
5      41     (1,2)          11 0.1111111
6      51     (1,2)           7 0.3333333
7      61     (1,1)           7 0.3333333
8      71     (1,1)          12 0.2222222
10     91     (1,1)           6 0.1111111
11    101     (1,2)           5 0.1111111
12    111     (1,2)          13 0.1111111
14    131     (1,2)          12 0.2222222
HTH
Petr
On 8 Feb 2006 at 9:40, Adrian Katschke wrote:
Date sent:      	Wed, 8 Feb 2006 09:40:43 -0800 (PST)
From:           	Adrian Katschke <adrian at atstatconsulting.com>
To:             	RHelp <r-help at stat.math.ethz.ch>
Subject:        	[R] adding variable into dataframe by indice
Petr Pikal
petr.pikal at precheza.cz