0

there

I have a variable <- c("apple", "banana", "orange"), and I also have a dataframe Mydata with colnames(Mydata) <- c("apple", "banana", "orange").

I want to write a for loop. Can I write it in this way?

for (i : length(variable)){
     Mydata$variable[i] == ......
}

This is just an simple example, the data in my hand is much more complicated. If I use Mydata$variable[i], R would tell me there is not any column named variable[i].

What should I do to actually make this happen? Thank you so much for helping!

f.lechleitner
  • 3,554
  • 1
  • 17
  • 35
Kimmy Li
  • 1
  • 1

0 Answers0