Skip to content
Prev 106738 / 398506 Next

coded to categorical variables in a large dataset

On Fri, 29 Dec 2006, sj wrote:

            
[...]

As Richard suggested you may not want to do this at all, but ...

If you want these as a matrix, this is fast and direct:

 	mat <- diag(5)[ test2, ]

If not as a matrix

 	event1 <- as.numeric( test2 == 1 )

is concise and

 	for (i in 1:5) assign(paste("event",i,sep=""), as.numeric( test2==i ))

is about as fast as you can get.

HTH,

Chuck


Charles C. Berry                        (858) 534-2098
                                          Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	         UC San Diego
http://biostat.ucsd.edu/~cberry/         La Jolla, San Diego 92093-0717