For a sample dataframe:
country = c("uk", "fr", "it")
N = c(100, 80, 95)
df <- data.frame(country, N)
I wish to populate two extra columns (say 'a_col' and 'b_col') in my 'df' dataframe with values calculated from a previous command. For simplicity, values for the UK to populate the two columns (first row) mentioned above would be:
a <- 5.5
b <- 3.6
How would I add these values to the dataframe in the right row? (i.e. for the UK only, not the other countries). If it could be wrapped up in a function, I guess that would be the easiest - could I use 'sapply'?