Skip to content
Prev 293949 / 398503 Next

convert 400 numeric variables to categorical together

Assuming the 400 numeric variables are integers this will be simpler if you
can identify the columns to be converted to factors as a block of column
numbers (e.g. 1:400, or 401:800)

# Create some data

X <- data.frame(matrix(nrow=20, ncol=20))
for (i in 1:10) X[,i] <- round(runif(20, .5, 5.5), 0)
for (i in 11:20) X[,i] <- rnorm(20)     
str(X) # structure of X

# convert numbers to factors for the first 10 columns

X2 <- X
for (i in 1:10) X2[,i] <- factor(X[,i])
str(X2)

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352