Sometimes it is necessary to declare variables as factors. For example, if they are items on a scale that need to be treated as ordinal and polychoric correlations will be estimated. This function takes as argument a data frame of such variables/items and declares them as “factors” (categorical variables with levels).

Num2Fac<- function(data) {
	data.f <- data
		for(i in 1:dim(data)[2]) {
		data.f[,i] <- as.factor(data[,i])

Created by Pretty R at

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

One Response to Num2Fac

  1. Pingback: EFA | latentPeriod

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s