I am pretty much new to R and am trying to prepare my data set in Rstudio for further analysis. I will be appreciative if anyone can help me find a solution for my code. My data is called m8. This is what I have done so far. But it only returns the max value between "U1High", "U1Low" and "U1Med" in the entire column "Q2". This is not What I want.
for (i in 1:length(m9[ , "condition"])) {
if(m9[m9$condition == "U1High", ] ||
m9[m9$condition == "U1Med", ]) {
if (m9[m9$condition == "U1High", ][ , "Subject"] == m9[m9$condition == "U1Med", ][ , "Subject"]) {
for (j in 1:length(max(m9[m9$condition == "U1High", ][ , "Q2"],
m9[m9$condition == "U1Med", ][ , "Q2"]))) {
m9$desktop.adjusted[i] = 1
}
}
}
}
I am trying to add values to the last column named "desktop.adjusted" based on two conditions on other columns. I have repeated measurements for each subject. I need to select “U1High”, “U1Low” and “U1Med” from the Condition column within each subject. This means that the subject number for “U1High”, “U1Med” and “U1Low” have to be equal. Then pick the max value for the correspondent rows on the Q2 column. Then turn the max value to 1 and put it on the desktop.adjusted column. Also the min value to 3 and add it to the desktop.adjusted column. The number between min and max has to be assigned as 2 and added to the "desktop.adjusted" column.
Any suggestions and help would be appreciated.