I have found a post, which is very similar to my problem. I have a data.frame with a list of keywords, which are separated by semicolons in one coloumn and the year in another column. I would like to unlist the keywords without losing the information about the year.
I can separate the keywords with strsplit and unlist
keywords <- unlist(strsplit(df$keywords,";"))
l1 <- sapply(df$keywords, length)
Year <- rep(df$Year, l1)
length(Year)
length(keywords)
dfkeywords=data.frame(Year=Year, Keywords=keywords, stringsAsFactors = F)
but I fail to generate a vector of the year that is the same length as the keywords vector.
How do I do that in a smart way?
Best Pete