Hi there,
I am switching from Stata, therefore please be kind with me.
I got a dataset of ratings in multiply categories and want to analyse them. My loop worked well, but now I want to know if the Interrater-Agreement is better when we exclude the first two observation of each rater.
Whatever I do if i write a simple code everything works well, exept I insert it within a loop. In Stata I could use a foreach loop and everywhere where I write `i' the it would use the current variable. This seems to be different in R. Can you give me a hint how the code should look like that every "i" is "v1" in the first round "v2" and so on.
Thank you
df.raw <- data.frame(
raterid = c(rep(1,10),rep(2,10),rep(3,10),rep(4,10),rep(5,10),rep(6,10)),
videoid = c(1,2,3,4,5,6,7,8,9,10),
num = sample(1:10),
v1 = sample(1:2, 3, replace=TRUE),
v2 = sample(1:2, 3, replace=TRUE),
v3 = sample(1:2, 3, replace=TRUE),
v4 = sample(1:2, 3, replace=TRUE),
v5 = sample(1:2, 3, replace=TRUE),
v6 = sample(1:2, 3, replace=TRUE)
)
#works
df<- df.raw %>%
select("raterid", "videoid", v1) %>%
spread("raterid", v1)
# dosn´t work
n <- c("v1") #Later, I want to insert all dimensions here.
for(i in n){
df <- df.raw %>%
mutate(i = replace(i, num < 3, NA)) %>%
select("raterid", "videoid", i) #%>% works after problem is solved
#spread("raterid", i)
}
Edit: Kind of Reprex & minor changes