I can't figure out what is wrong with this code. I have a dataframe called Fish. I want to add a column called CombineMe that is default 0. The value would change to 501 if it meets the two criteria (either the data source = A & sample method = visual then it would equal 501 and also if the data source = B & taxon code is the three EJ, EL or RV). I can't quite figure out where I'm going wrong. I've tried adjusting where the [i] are and adding commas...
for(i in 1:length(Fish)) {
Fish$CombineMe <- 0
if (Fish$data_source == "A" & Fish$sample_method == "visual") {
Fish$CombineMe [i] <- 501
} else if (Fish$data_source == "B" & Fish$taxon_name == c("EJ", "EL", "RV")){
Fish$CombineMe [i] <- 501
}}
Here's a condensed example of what Fish looks like:
Fish <- data.frame ("data_source"=c("A", "A", "B", "C", "C", "D", "D"), "sample_method"= c("visualfish", "fish", "fish", "fish", "fish", "fish", "fish"),
"taxon_name"=c("EJ", "EJ", "RV", "EJ", "RV", "EL", "HR"))