I am new to Stackoverflow and haven't found a topic that could already answer my question so I am posting it here now!
I am trying to change yes/no-characters in a dataframe to integers 1 and 2. I want to do this for only four out of 45 subjects. I wanted to go for a for loop with an ifelse-statement to do this. The loop seems to work at first but there is no change in my dataframe when I open it or have a look with head(data).
The dataframe is called "gatingdata" and the column "correct_buttonBox".
This is what I did:
ffor row in 1:nrow(gatingdata$correct_buttonBox)) {
if (gatingdata$subject_nr == "19") {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} if (gatingdata$subject_nr == "27") {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} if (gatingdata$subject_nr == "35") {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} if (gatingdata$subject_nr == "42") {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
}
}
I have also tried:
for(row in 1:nrow(gatingdata$correct_buttonBox)) {
which[(gatingdata$subject_nr == "19"),] {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} which[(gatingdata$subject_nr == "27"),] {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} which[(gatingdata$subject_nr == "35"),] {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
} which[(gatingdata$subject_nr == "42"),] {
ifelse(gatingdata$correct_buttonBox=="no", 1, 2)
}
}
I also tried using " i in 1:length(data$column)". Didn't work either.
I would be very thankful if somebody could tell me what I'm doing wrong! I couldn't find any information related to my problem in an online search and I've been trying to solve this for several hours now. This is the 7th or 8th version of the loop but to me, this seems like the most logic....
Best,
M.H.
Aucun commentaire:
Enregistrer un commentaire