[R] help recoding

Selwyn Mccracken selwyn.mccracken at stonebow.otago.ac.nz
Tue Jun 17 08:13:20 CEST 2003


sorry,
I was a bit hasty with the send button. I have managed to solve it by
doing the following: 

q = c()
for (i in p) q = c(q, cause$nds[cause$acc==i])

I would however be interested in knowing how to apply the transform in
this case properly.

S.

Quoting Selwyn McCracken <selwyn.mccracken at paradise.net.nz>:

> hi R-listers,
> 
> I would like some help recoding a variable. I have a dataframe 'cause'
> 
> that translates between a set of codes:
> 
> acc	nds
> -	-
> 1	2
> 3	4	
> 5	8
> ...	...
> 
> the desired result for dataframe 'p':
> a
> -
> 1
> 5
> 5
> 
> would be:
> a	b
> -	-
> 1	2
> 5	8
> 5	9
> 
> I have tried:
> 
> transform(p, b=cause$nds[cause$acc==p$a])
> 
> but for some reason it complains about the difference in length between
> 
> the translation and result dataframes.
> 
> This prints the desired result, but I am unsure how to collect the 
> results into a variable.
> 
> for (i in p) print cause$nds[cause$acc==i]
> 
> Any help greatly appreciated.
> 
> Selwyn
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list