I want to create a for loop in R, but it should depend on the last letter in 17 variables, and I have trouble finding out how to make the function see the variable name as a string.
The code I have now:
fisher.test(table( data.family$proband.unrelated, data.family$q_81_SQ00a))
fisher.test(table( data.family$proband.unrelated, data.family$q_81_SQ00b))
fisher.test(table( data.family$proband.unrelated, data.family$q_81_SQ00c))
As you can see, i just keep on repeating the code for each variable from the letter a to r, so i want to create a for loop, which can change the last letter of the variable q_81_SQ00a to the letters a-r.
for (i in c('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r')) {
fisher.test(data.family$proband.unrelated, data.family$q_81_SQ00'i'))
}
I get the warning "unexpected symbol" for several places in the code. Thanks in advance!