1

I have a data frame where one of the columns is strings:

> head(a$type)
[1] Sell Sell Sell Buy  Buy  Buy 
Levels: Buy Sell

When I append to it, it converts everything to an int:

> head(append(a$type, "Buy"))
[1] "2" "2" "2" "1" "1" "1"

Why does this happen, and how can I prevent it?

Sam Lee
  • 9,913
  • 15
  • 48
  • 56
  • 4
    You actually have a factor, not a string. – Peyton Jul 19 '13 at 21:10
  • ...and even then, nothing has (technically) been converted to an int. The factor was _already_ integer codes, and what you've gotten back are those integers converted to characters. – joran Jul 19 '13 at 21:13
  • Duplicate: http://stackoverflow.com/q/3443576/946850 – krlmlr Jul 19 '13 at 21:23

1 Answers1

3

Your a$type variable is actually a factor. To convert a factor to a character, use

a$type = as.character(a$type)

And then your append command should work.

slammaster
  • 855
  • 6
  • 11