Hi,
My dataframe has the form as below:
City Year Name
a 2011
b 2011
c 2011
a 2012
b 2012
c 2012
....
I want to fill column Name with values from vector names<-c("Joh", "Mary") so for every city and every year I will have an occurrence of name.
For example I want to see :
City Year Name
a 2011 John
b 2011 John
c 2011 John
a 2012 John
b 2012 John
c 2012 John
......
and so on for Mary etc..
I tried with :
df$Name[which(df$region=="a" & df$Year == 2011)]<-names2011[1:100]
df$Name[which(df$region=="b" & df$Year == 2011)]<-names2011[1:100]
df$Name[which(df$region== "c" & df$Year == 2011)]<-names2011[1:100]
but then df$Name results in list which is wrong.
Please help
Regards