Hi everybody,
I would like to look for help.
ownership<-data.frame(
ticker = as.factor(c("AAA", "AAM", "AAT", "ABS", "ABT", "ACC", "ACL",
"ADS", "AGF", "AGM")),
X2008 = as.factor(c(" ", " ", " ", " ", " ", "0.17%", " ", " ",
"19.87%", " ")),
X2009 = as.factor(c(NA, "0.36%", NA, NA, "19.22%", NA, "6.35%", NA,
"7.65%", NA)),
X2010 = as.factor(c("3.99%", "1.44%", NA, NA, "15.60%", NA, "4.44%", NA,
"5.24%", NA)),
X2011 = as.factor(c("10.42%", "1.50%", NA, NA, "9.20%", "1.64%",
"4.34%", NA, "4.10%", NA)),
X2012 = as.factor(c("21.61%", "2.65%", NA, NA, "7.21%", "7.68%",
"5.78%", NA, "2.92%", "1.75%")),
X2013 = as.factor(c("21.09%", "2.55%", NA, NA, "6.78%", "13.45%",
"4.98%", NA, "1.47%", "2.61%")),
X2014 = as.factor(c("20.59%", "0.97%", NA, NA, "7.47%", "16.50%",
"3.79%", NA, "1.10%", "0.00%")),
X2015 = as.factor(c("19.13%", "0.49%", NA, NA, "7.53%", "16.53%",
"3.69%", NA, "0.79%", "0.00%"))
)
df<-data.frame(
year = c(2010L, 2009L, 2006L, 2009L, 2007L, 2015L, 2010L, 2016L, 2002L,
2012L),
ticker = as.factor(c("AAA", "AAM", "ABT", "ACC", "ACL", "ACM", "ADC",
"ADS", "AGF", "AGM")),
date = as.factor(c("15-07-10", "24-09-09", "25-12-06", "22-12-09",
"05-09-07", "23-07-15", "24-12-10", "29-06-16",
"03-05-02", "14-12-12"))
)
I would like to add a new variable named "percent" to data frame df.
This variable "percent" are extracted based on the variable year and ticker from the ownership data frame. In excel I use the index and match function for this. How would it run in R?
I appreciate any help
Thank you in advance.
Best regards,