Skip to content

apply the function "factor" to multiple columns

2 messages · Bliese, Paul D LTC USAMH, Dimitris Rizopoulos

#
you could try this way:

dat <- data.frame(V1 = factor(1:3), V2 = factor(1:3), V3 = 
factor(1:3))
dat[1:3] <- lapply(dat[1:3], factor, labels = c("None", "Low Impact", 
"MedHigh Imp"))
dat


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Bliese, Paul D LTC USAMH" <paul.bliese at us.army.mil>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, May 31, 2005 10:42 AM
Subject: [R] apply the function "factor" to multiple columns