search for: getcatcolumns

Displaying 1 result from an estimated 1 matches for "getcatcolumns".

2008 Apr 24
1
Extracting factor columns from a data frame
Hi All, I have attempted to extract only the factor columns from an existing data set inside a loop without success . I tried the transform function which worked, but not inside the loop (attempts with cbind did not work either - inside a loop). Here is my function: getcatcolumns<-function(x) { # ignore type checking for data frames etc res <- data.frame() for(i in 1:length(x)) { if (class(x[,i]) =="factor") res <- transform(res, colname = x[,i]) # append the factor column to the new data frame (res) } return(res) } T...