[R] Help converting a data.frame to ordered factors

Phil Spector spector at stat.berkeley.edu
Tue May 3 00:00:12 CEST 2011


Robert -
    It would be helpful to know what you've tried that didn't
work, but the data.frame() function is the usual way of combining
things like this:

> a = factor(sample(1:5,100,replace=TRUE),ordered=TRUE)
> b = factor(sample(1:5,100,replace=TRUE),ordered=TRUE)
> ab = data.frame(a,b)
> sapply(ab,class)
      a         b 
[1,] "ordered" "ordered"
[2,] "factor"  "factor"

In particular cbind() and matrix() will not work properly for
what you're trying to do.

Of course, if you explained exactly how you're creating the 
96x34 array, there might be a better solution.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Mon, 2 May 2011, Robert Cassidy wrote:

> I have a 96x34 array of Likert scale data (96 cases, 34 items) of
> ordered factors (strongly disagree, disagree, neutral, agree, strongly
> agree) that are coded numerically (1 through 5).
>
> I cannot seem to convert this array (in any class) into ordered vectors.
>
> I have all the cases as vectors of ordered factors, but any which way
> I reassemble those vectors loses the ordered factors and converts back
> to numbers.
>
> Can someone tell me how to either convert the data.frame into ordered
> factors OR how to assemble the vectors (of ordered factors) into an
> array that preserves the factors.
>
> Many thanks in advance for any help.
> Robert
>
>
> -- 
> Robert Cassidy, PhD
> Department of Psychology
> Concordia University
> 7141 Sherbrooke W.
> Montreal (QC) H4B 1R6
> tel: (514) 848-2424 x2244
> fax: (514) 848-4523
> office: PY-119.2
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list