Cognitive Semiotics
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Binomial into binary

Go down

Binomial into binary Empty Binomial into binary

Post by Santiak Tue Apr 19, 2016 3:07 pm

As always, this is likely just one possible solution:

df$v <- as.numeric(as.character(factor(df$v, c("name1", "name2"), labels = c(1, 0))))

"df" is the name of your dataframe
"v" is the name of the variable containing the values you want to turn into binary.



Alternatively, you can use:
df$v <- as.numeric(df$v)-1

Just be aware that it doesn't discriminate correct from incorrect, but assigns the value based on when the value appeared, so if you used a randomized paradigm, you might end up with some vectors having their "correct" listed as 1, but "incorrect" as 1 in others.



If all else fails, you can manually correct your dataframe by doing:
fix(df)
Which will bring up a small window where you can replace the values directly.

Santiak
Admin

Posts : 23
Join date : 2016-02-24

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum