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
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.
>
Thanks, Phil. I could have sworn that I tried that (several times). It works perfectly, of course. Thanks again, Robert -- View this message in context: http://r.789695.n4.nabble.com/Help-converting-a-data-frame-to-ordered-factors-tp3490838p3492705.html Sent from the R help mailing list archive at Nabble.com.
Hi again, Now that I have the data.frame as ordered factors, when I try to transpose it, I lose the factor orders.> datfact<-data.frame(c1,c2,c96) > sapply(datfact, class)c1 c2 c96 [1,] "ordered" "ordered" "ordered" [2,] "factor" "factor" "factor"> > dafacT<-as.data.frame(t(datfact)) > sapply(datfacT,class)item1 item2 item3 item4 ... "factor" "factor" "factor" "factor" ...> >Is there a simple way to re-impose ordering on the transposed df? or alternatively to transpose the df without losing the ordering? Many thanks, Robert -- View this message in context: http://r.789695.n4.nabble.com/Help-converting-a-data-frame-to-ordered-factors-tp3490838p3492979.html Sent from the R help mailing list archive at Nabble.com.