[R] help recoding

Spencer Graves spencer.graves at pdf.com
Tue Jun 17 14:50:38 CEST 2003


Have you considered the following:

 > nds <- c(2, 4, 8)
 > names(nds) <- c(1, 3, 5)
 > nds[c("3", "1", "5")]
3 1 5
4 2 8

hth.  spencer graves

Selwyn Mccracken wrote:
> 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
>>
> 
> 
> ______________________________________________
> 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