2

Here's the dput for my list:

structure(c(5L, 3L, 1L), .Label = c("id0", "id1", "id2", "id3",
"id4"), class = "factor")

which, when we use print() outputs

[1] id4 id0 id2

Which is what I want minus the [1]

To be rid of that, I use cat(), but when I do, this is output instead

5 3 1

Which seems to correspond to the c(5L,3L,1L) bit above, but I don't understand why.

Cheers!

3
  • 3
    Because your "list" is really a "factor"... convert it to character and you will get what you expect. Jul 26, 2012 at 20:45
  • Quick! Submit the answer so I can mark it correct! Jul 26, 2012 at 20:50
  • Not very quick, but there you go... Jul 26, 2012 at 21:10

1 Answer 1

1

Because your "list" is really a factor... convert it to character and you will get what you expect.

> l <- structure(c(5L, 3L, 1L), .Label = c("id0", "id1", "id2", "id3",
+ "id4"), class = "factor")
> cat(l, "\n")
5 3 1
> cat(as.character(l),"\n")
id4 id2 id0 

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.