I'm taking a self-study introductory class in R, and the question is:
Use the
grep()function to find the indices of the letter "x" and find the frequency of "a" from the randomletters vector.
The vector is already given:
set.seed(10)
randomletters <- letters[sample(1:26, 100, replace = T)]
I run the code grep("x",randomletters) and I get 11, 18, 41, and 65 for the indices. The answers that I got are not in the list of answers to choose from.
I run the code grep("a",randomletters) and I get 4 as the frequency and it is the wrong answer.
Am I doing something wrong?

You have the correct answer in both cases.
The answer key in your image includes 34 for the indices instead of the 4 values you saw. That probably indicates that it was produced using the buggy version of the
sample()function that was fixed in early 2019. You can use that version by runningI don't recommend doing this for any reason except reproducing obsolete results.
Once you're done checking answers against that answer key, you can return it to normal using