I have a dataset with multiple journal articles in it. The different articles all have different identification codes (WoS_No). Different articles are on different rows.
These articles have different numbers of authors. If a paper has more than 1 author, the identification code gets duplicated over multiple rows, with one row per author.
There is other information in the df, some of which relates to the paper (and is the same for all rows with the same WoS_No code. But, some relates to the authors only (like their faculty) which is then printed out over rows.
Please see example below:
# Original df
df <- data.frame("WoS_No" = matrix(c("WOS:000352315900021", "WOS:000352315900021", "WOS:000352315900021", "WOS:000352315900021", "WOS:000362644700013", "WOS:000362644700013", "WOS:000382460200025", "WOS:000381736200014", "WOS:000371540200019"), 9, 1))
df$Author <- c("CHENEVIX, Georg", "CHENEVIX, Georg", "DOLCE, Ric", "DOLCE, Ric", "CLOUST, A", "STEVEN, A", "WANG, Zhi", "COIN, L", "BARL, Kare")
df$Faculty <- c("Medicine", NA, "HASS", NA, "HABS", "Medicine", "Medicine", "IMB", NA)
df$CNCI <- c(10.51, 10.51, 10.51, 10.51, 37.47, 37.47, 0.84, 8.05, 29.41)
sapply(data2, class)
I would really like to have the df arranged so there is only 1 row per article (i.e., one WoS_No per row).
I would like the author names to be split out into different columns (see 'Author1', 'Author2' columns below). I tried converting from long to wide format, but it did not work, possibly because the authors are different on most articles - so it gave each name a new column (which I cannot have as there are about 20,000 names)
If this is too fiddly, I would be happy with all author names collapsed into one string in an 'Authors' column, with all names separated by a semicolon (meaning I could just strsplit them later when needed). See 'Faculties' column below.
# New df options
dfnew <- data.frame("WoS_No" = matrix(c("WOS:000352315900021", "WOS:000362644700013", "WOS:000382460200025", "WOS:000381736200014", "WOS:000371540200019"), 5, 1))
dfnew$Author1 <- c("CHENEVIX, Georg", "CLOUST, A", "WANG, Zhi", "COIN, L", "BARL, Kare")
dfnew$Author2 <- c("DOLCE, Ric", "STEVEN, A", "", "", "")
dfnew$Faculties <- c("Medicine; NA; HASS; NA", "HABS; Medicine", "Medicine", "IMB", "NA")
dfnew$CNCI <- c(10.51, 37.47, 0.84, 8.05, 29.41)
I tried for looping through each WoS_No and collapsing one by one, but because I have 68,000 WoS_No's this was failing to finish in a sensible time.
I am really stumped and would very much appreciate any help anyone could give me.

