I'm having trouble with what I think is a basic R task.
Here's my sample dataframe named 'b'
Winner Color Size
Tom Yellow Med
Jerry Yellow Lar
Jane Blue Med
where items in the Winner column are factors.
I'm trying to change "Tom" in the dataframe to "Tom LLC" and I can't get it done.
Here's what I tried:
Simple way:
b$winner[b$winner=='Tom'] = as.factor('Tom LLC')
but that failed with "invalid factor level, NAs generated"
Next I tried a more advanced route:
name_reset = function (x, y, z) {
if (x$winner == y) {x$winner = z}
}
b = adply(b,1,name_reset,'Tom','Tom LLC')
but that failed with "Error in list_to_dataframe(res, attr(.data, "split_labels")) : Results are not equal lengths"
I feel I'm missing something basic. Can someone redirect me or offer suggestions on the code I wrote above? Thank you very much