I am practicing loops and trying to figure out how to print ___ is a good friend if their number is odd (through an assigned number in a vector) - why won't it print the names of the people in the vector who are coded as odd numbers?
B_list <- c(Bob=1, Bill=2, Buddy=3) # create character vector
phrase <- "is a good friend"
for (i in B_list){
if((i %% 2) != 0)
print(paste(names(i),phrase))
}
Output:
[1] " is a good friend"
[1] " is a good friend"
names(B_list)[i]. You tried to get the name of 1. It doesn't have a name, it's just a number. You should have gotten an error and then searched SO with selected parts of the error message.