2

I created a vector, marks:

marks <- cut(scores[,1], breaks = break_vector, labels = mark_vector, right = FALSE)

Calling marks gives: [1] 3 2 4 4 2 5 2 1

That’s fine. Now I want to create a matrix, having scores in the first, and marks in the second column.

Then I use marks_column <- cbind(marks) before creating that matrix. There is the problem: In the output of R I now get a column, ignoring the labels = mark_vector from the cut function above. So the R output gives a column, as if I had written labels = FALSE insted of labels = mark_vector.

How can I fix that?

rawr
  • 20,481
  • 4
  • 44
  • 78
J. Kranz
  • 31
  • 2
  • 6
    `cbind` coerces to a matrix, and as the results oc `cut` is a factor, it coerces to the levels of the factor ie 1,2,3 . So either use a dataframe to store your cut vector or set convert it to a character before using cbind. – user20650 Aug 31 '17 at 14:30
  • 1
    @user20650 I think that'll work as an answer! – MichaelChirico Aug 31 '17 at 14:40
  • 1
    `cbind.data.frame(cut(rnorm(100), 6))` – rawr Aug 31 '17 at 15:02
  • 2
    Possible duplicate of [cbind returns index of factor vector](https://stackoverflow.com/questions/24866356/cbind-returns-index-of-factor-vector) ; also relevant https://stackoverflow.com/questions/23567625/cbind-replaces-string-with-number – user20650 Aug 31 '17 at 16:40
  • 2
    @MichaelChirico ;cheers, though probably best to mark it as a duplicate – user20650 Aug 31 '17 at 16:42

0 Answers0