I have a dataframe (df) with a column of type strings such as
code country
DK Denmark
DE Germany
BEB Belgium
B Brazil
And I wont to write a for loop that prints the countries starting with B. This is how I approach it but I get an error:
for (i in unique(df$country)) {
if (i == grep("^B", unique(df$country), value = TRUE)) {
print(i)
}
}
Error:
Error in if (i == grep("^B", unique(df$country), value = TRUE)) { :
the condition has length > 1