Home > Blockchain >  Separate variable by ";" and create new row
Separate variable by ";" and create new row

Time:05-26

In my dataset, I have an actor variable which captures all actors that were present at one event. However, when multiple actors attended the same event, they are listed all in the same cell separated by a ";", e.g., "military;veterans;activists".

If this is the case I need to create an actor2 and actor 3 variable out of the actor variable, still in the same row. Any suggestions on how to do this? Here is my data:

structure(list(id = c(6040L, 5999L, 5997L, 6238L, 8233L, 6956L, 
6957L, 6034L, 6030L, 5967L, 5993L, 6168L, 6037L, 6032L, 6024L, 
6022L, 6026L, 6172L, 6169L, 6038L, 6203L, 6236L, 6801L, 6870L, 
6911L, 6912L, 6914L, 6915L, 6974L, 6968L, 6970L, 7148L, 7282L, 
7280L, 7281L, 281L, 307L, 278L, 309L, 313L, 455L, 465L, 466L, 
495L, 523L, 48L, 49L, 54L, 56L, 55L, 53L, 58L, 57L, 65L, 64L, 
66L, 81L, 80L, 82L, 88L, 129L, 127L, 125L, 123L, 130L, 131L, 
118L, 120L, 121L, 122L, 126L, 132L, 458L, 79L, 457L, 5976L, 5977L, 
5975L, 5983L, 5994L, 6031L, 6167L, 6023L, 6025L, 6237L, 280L, 
78L, 77L, 76L, 119L, 128L, 124L, 5996L, 461L, 6954L, 6955L, 6953L, 
6951L, 270L, 5995L), cowcode = c(552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 552L, 
552L, 552L, 552L, 552L, 552L, 552L, 552L), location = c(879233L, 
882229L, 882229L, 884979L, 886763L, 887854L, 887854L, 890189L, 
890189L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 890299L, 
890299L, 890422L, 890422L, 893697L, 894701L, 894701L, 894701L, 
894701L, 894701L, 894701L, 894701L, 894701L, 894701L, 894701L, 
894701L, 894701L, 894701L, 894701L, 894701L, 894701L, 894701L, 
895061L, 895061L, 895269L, 895269L, 895269L, 895269L, 1106542L, 
7453772L), latitude = c(-17.83028, -17.85472, -17.85472, -18.9707, 
-20.06373, -18.30404, -18.30404, -17.88547, -17.88547, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -17.82772, -17.82772, -17.82772, -17.82772, 
-17.82772, -17.82772, -19.45, -19.45, -17.36667, -20.15, -20.15, 
-20.15, -20.15, -20.15, -20.15, -20.15, -20.15, -20.15, -20.15, 
-20.15, -20.15, -20.15, -20.15, -20.15, -20.15, -20.15, -17.30192, 
-17.30192, -22.21667, -22.21667, -22.21667, -22.21667, -18.01274, 
-19.50077), longitude = c(30.98222, 30.99, 30.99, 32.67086, 30.82766, 
31.19832, 31.19832, 30.9927, 30.9927, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 31.05337, 
31.05337, 31.05337, 31.05337, 31.05337, 29.81667, 29.81667, 30.2, 
28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 
28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 28.58333, 
28.58333, 28.58333, 28.58333, 31.33056, 31.33056, 30, 30, 30, 
30, 31.07555, 31.63936), asciiname = c("Warren Park", "Rugare", 
"Rugare", "Mutare", "Masvingo", "Mahusekwa", "Mahusekwa", "Highfield", 
"Highfield", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Harare", "Harare", "Harare", "Harare", "Harare", 
"Harare", "Harare", "Gweru", "Gweru", "Chinhoyi", "Bulawayo", 
"Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", 
"Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", 
"Bulawayo", "Bulawayo", "Bulawayo", "Bulawayo", "Bindura", "Bindura", 
"Beitbridge", "Beitbridge", "Beitbridge", "Beitbridge", "Chitungwiza", 
"Mutare"), event_date = c("2003-06-03", "2003-03-18", "2003-03-18", 
"2003-11-18", "2010-11-07", "2008-03-09", "2008-03-09", "2003-06-02", 
"2003-06-02", "2003-02-07", "2003-03-18", "2003-06-02", "2003-06-02", 
"2003-06-02", "2003-06-02", "2003-06-02", "2003-06-02", "2003-06-02", 
"2003-06-03", "2003-06-03", "2003-07-08", "2003-11-18", "2006-02-21", 
"2007-02-18", "2007-08-29", "2007-08-29", "2007-11-30", "2007-11-30", 
"2008-04-04", "2008-04-04", "2008-04-04", "2008-05-24", "2008-06-27", 
"2008-06-27", "2008-06-28", "2013-07-28", "2013-07-28", "2013-07-28", 
"2013-07-28", "2013-08-12", "2014-09-04", "2014-10-28", "2014-10-30", 
"2015-04-11", "2015-11-19", "2016-02-18", "2016-02-24", "2016-04-14", 
"2016-04-14", "2016-04-14", "2016-04-14", "2016-05-25", "2016-05-25", 
"2016-07-20", "2016-07-20", "2016-07-21", "2016-08-17", "2016-08-17", 
"2016-08-24", "2016-09-09", "2017-11-18", "2017-11-18", "2017-11-18", 
"2017-11-18", "2017-11-18", "2017-11-18", "2017-11-18", "2017-11-18", 
"2017-11-18", "2017-11-18", "2017-11-18", "2017-11-20", "2014-10-07", 
"2016-08-13", "2014-10-04", "2003-02-28", "2003-02-28", "2003-02-28", 
"2003-03-04", "2003-03-18", "2003-06-02", "2003-06-02", "2003-06-02", 
"2003-06-02", "2003-11-18", "2013-07-27", "2016-08-06", "2016-08-06", 
"2016-08-06", "2017-11-18", "2017-11-18", "2017-11-18", "2003-03-18", 
"2014-10-17", "2008-02-23", "2008-02-23", "2008-02-23", "2008-02-23", 
"2013-07-17", "2003-03-18"), side = c(1L, 1L, 1L, 1L, 0L, 0L, 
0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 
0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L), actors = c("opposition supporters", 
"youths", "opposition supporters;youths", "", "ZANU PF supporters", 
"villagers", "villagers", "opposition supporters", "opposition supporters", 
"Movement for Democratic Change activists", "opposition supporters", 
"opposition protesters", "students", "students", "students", 
"opposition supporters", "opposition protesters", "students", 
"anti-government protesters", "opposition supporters", "supporters of Movement for Democratic Change", 
"", "women;National Constitutional Assembly members", "opposition party supporters", 
"Zimbabwe War Veterans Association members", "Mugabe supporters", 
"Mugabe supporters", "Mugabe supporters", "war veterans", "war veterans", 
"guerrilla war veterans", "Mugabe supporters", "Mugabe supporters", 
"Mugabe supporters", "Mugabe supporters", "ZANU PF party supporters", 
"ZANU PF party supporters", "ZANU PF party supporters", "ZANU PF party supporters", 
"ZANU PF party supporters", "supporters of president Mugabe", 
"", "", "Zimbabwe Congress of Trade Unions", "ruling party supporters", 
"war veterans;youth activists", "youth;opposition", "opposition", 
"opposition Movement for Democratic change", "supporters of Movement for Democratic Change", 
"supporters of Movement for Democratic Change", "youth league", 
"", "ruling party ZANU PF", "ruling party ZANU PF", "members of ruling party ZANU PF", 
"", "", "supporters of the Movement for Democratic Change", "youth protest movement", 
"military", "", "", "", "military;veterans;activists", "", "independence war veterans;ruling party barons;army", 
"supporter of pastor Evan Mawarire", "army", "veterans;members of Mugabe's government", 
"", "students", "supporters of ZANU PF party", "members of the Tsvangirai's Movement for Democratic Change;members of Zimbabwe People First", 
"Grace Mugabe supporters", "cricket fans", "cricket fans", "cricket fans", 
"", "opposition supporters", "opposition supporters", "opposition supporters", 
"opposition supporters", "opposition supporters", "", "ZANU PF party supporters", 
"cricket viewers;graduates", "members of the Woman of Zimbabwe Arise group", 
"cricket viewers", "", "", "", "opposition supporters", "ZANU PF party supporters", 
"Mugabe supporters", "Mugabe supporters;school children", "Mugabe supporters", 
"Mugabe supporters", "ZANU PF party supporters", "opposition supporters"
), issue = c("against:Mugabe's repressions", "against:Mugabe's government", 
"against:Mugabe's government", "against:Mugabe's autocratic rule", 
"for:Mugabe to rule the country", "for:Mugabe", "for:Mugabe", 
"against:Mugabe's government", "against:Mugabe's policies", "against:Mugabe;against:visit of Olusegun Obasanjo", 
"against:Mugabe's government", "against:Mugabe's government", 
"against:Mugabe's government", "against:Mugabe's policies", "for:Mugabe to step down", 
"for:Mugabe to step down", "for:Mugabe to step down", "for:resignation of President Mugabe", 
"against:Mugabe's government", "against:Mugabe's government", 
"for:Mugabe to step down;for:transitional government", "against:Mugabe's autocratic rule", 
"against:Mugabe's birthday celebration", "against:deteriorating living conditions;against:Mugabe to postpone presidential elections", 
"for:Mugabe;against:Western imperialism", "against:western critics;for:Mugabe", 
"for:Mugabe's presidential candidature", "for:Mugabe's presidential candidature", 
"for:Mugabe", "for:Mugabe", "for:Mugabe", "for:open campaign;for:Mugabe as president", 
"for:revolution;for:vote for Mugabe", "for:revolution;for:voting for Mugabe", 
"for:revolution;for:voting for Mugabe", "for:Mugabe campaign", 
"for:Mugabe campaign", "for:Mugabe campaign", "for:Mugabe campaign", 
"for:reelected president Mugabe", "for:Mugabes wife Grace to lead the ruling party's women's wing", 
"for:Mugabe's resignation", "for:Mugabe and his wife", "for:Mugabe to fix ailing economy;for:two million new jobs", 
"for:president Mugabe's next presidential bid", "against:Mugabe's succession", 
"against:Birthday party for Mugabe", "against:Mugabe's misrule", 
"against:Mugabe", "against:Mugabe", "against:Mugabe", "for:Mugabe's rule for life", 
"for:Mugabe's rule", "for:Mugabe's rule", "for:Mugabe's rule", 
"for:Mugabe's rule", "against:Mugabe's succession", "against:Mugabe's economy policies", 
"against:Mugabe", "against:police brutality;against:Mugabe", 
"for:Mugabe's resignation", "for:Mugabe's resignation", "for:Mugabe's resignation", 
"for:Mugabe's resignation", "for:Mugabe's resignation", "for:Mugabe's resignation", 
"for:Mugabe's resignation", "for:Mugabe's resignation", "for:Mugabe's resignation", 
"for:Mugabe's resignation", "for:Mugabe's resignation", "for:Mugabe's resignation", 
"against:party division;for:presidency of Robert Mugabe", "against:Mugabe's economy policies", 
"against:Western aid;for:presidency of Robert Mugabe", "against:Mugabe;for:justice", 
"against:Mugabe;for:justice", "against:Mugabe;for:justice", "against:Mugabe", 
"against:Mugabe's government", "against:Mugabe's policies", "against:government;against:Mugabe's dictatorial rule", 
"for:Mugabe to step down", "for:Mugabe to step down", "against:Mugabe's autocratic rule", 
"for:Mugabe campaign", "against:Mugabe", "against:Mugabe's economy policies", 
"against:Mugabe's succession", "for:Mugabe's resignation", "for:Mugabe's resignation", 
"for:Mugabe's resignation", "against:Mugabe's government", "against:contenders of Robert Mugabe", 
"against:regime change;for:celebrating Mugabe's birthday", "for:Mugabe's birthday", 
"for:celebrating Mugabe's birthday;for:kicking off election campaign", 
"for:Mugabe's birthday;for:campaign start", "for:Mugabe campaign", 
"against:Mugabe's government"), scope = c(0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), 
    part_violence = c(NA, 1L, 1L, NA, NA, NA, NA, NA, 1L, NA, 
    1L, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, NA, NA, 
    0L, NA, NA, NA, NA, NA, NA, 1L, 1L, 1L, NA, NA, NA, NA, NA, 
    NA, 0L, NA, NA, NA, NA, NA, 0L, NA, 0L, NA, NA, 0L, 0L, 0L, 
    NA, NA, NA, 1L, 0L, 0L, NA, 0L, 0L, 0L, 0L, NA, NA, 1L, NA, 
    0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, 1L, NA, NA, NA, NA, 
    NA, NA, NA, 0L, 0L, NA, NA, NA, NA, NA, NA, NA, NA, 3L, NA
    ), sec_engagement = c(2L, 2L, 2L, 2L, NA, NA, NA, 3L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    NA, 1L, NA, NA, 1L, 1L, 1L, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, 2L, NA, NA, NA, 2L, NA, NA, NA, 1L, 1L, NA, 1L, NA, 
    NA, NA, 2L, 2L, 2L, 2L, 1L, NA, 1L, 1L, NA, 1L, NA, NA, NA, 
    NA, 1L, NA, NA, NA, NA, 2L, NA, 2L, 2L, NA, 2L, 2L, 2L, 2L, 
    2L, NA, 1L, 1L, NA, NA, NA, 1L, NA, NA, NA, NA, NA, NA, NA, 
    NA), numparticipants = c("", "", "", "", "300;500", "several thousands", 
    "several thousands", "", "", "20", "", "", "", "", "hundreds", 
    "", "", "", "", "", "30", "200", "", "", "5000", "thousands", 
    "thousands", "thousands", "400", "400", "hundreds;400", "", 
    "", "", "", "40000", "40000", "", "30000", "thousands", "hundreds", 
    "", "hundreds", "200", "5000", "", "", "thousands", "2000", 
    "2000", "2000", "thousands", "30000;60000", "tens of thousands", 
    "thousands", "thousands", "several hundreds", "hundreds", 
    "200", "30", "", "thousands", "thousands", "tens of thousands", 
    "thousands", "tens of thousands", "10000", "", "thousands", 
    "10000", "thousands", "several hundreds", "", "thousands", 
    "hundreds", "", "", "", "", "", "500", "", "", "", "", "", 
    "", "", "hundreds", "", "", "", "", "", "", "", "", "thousands", 
    "", ""), avg_numparticipants = c(NA, NA, NA, NA, 400L, 2000L, 
    2000L, NA, NA, 20L, NA, NA, NA, NA, 200L, NA, NA, NA, NA, 
    NA, 30L, 200L, NA, NA, 5000L, 2000L, 2000L, 2000L, 400L, 
    400L, 300L, NA, NA, NA, NA, 40000L, 40000L, NA, 30000L, 2000L, 
    200L, NA, 200L, 200L, 5000L, NA, NA, 2000L, 2000L, 2000L, 
    2000L, 2000L, 45000L, 15000L, 2000L, 2000L, 200L, 200L, 200L, 
    30L, NA, 2000L, 2000L, 15000L, 2000L, 15000L, 10000L, NA, 
    2000L, 10000L, 2000L, 200L, NA, 2000L, 200L, NA, NA, NA, 
    NA, NA, 500L, NA, NA, NA, NA, NA, NA, NA, 200L, NA, NA, NA, 
    NA, NA, NA, NA, NA, 2000L, NA, NA), source = c("The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "The Associated Press", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "The Associated Press", 
    "The Associated Press", "The Associated Press", "The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "The Associated Press", 
    "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "The Associated Press", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "The Associated Press", 
    "The Associated Press", "The Associated Press", "Agence France Presse -- English", 
    "The Associated Press", "The Associated Press", "The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "The Associated Press", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English", "The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "The Associated Press", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "The Associated Press", "Agence France Presse -- English", 
    "The Associated Press", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English", "The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "The Associated Press", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "The Associated Press", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "BBC Summary of World Broadcasts", "Agence France Presse -- English", 
    "Agence France Presse -- English", "The Associated Press", 
    "The Associated Press", "The Associated Press", "The Associated Press", 
    "The Associated Press", "The Associated Press", "Agence France Presse -- English", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "The Associated Press", 
    "Agence France Presse -- English", "Agence France Presse -- English", 
    "Agence France Presse -- English", "BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring", 
    "Agence France Presse -- English"), version = c(1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
    2L, 1L, 1L, 1L, 1L, 2L, 1L)), class = "data.frame", row.names = c(NA, 
-100L))

CodePudding user response:

We can use separate_rows to split the 'actors' column at the ; to create new rows

library(tidyr)
library(dplyr)
df1 %>% 
   separate_rows(actors, sep = ";")

If we need new columns, use separate

library(stringr)
out <- df1 %>%
    separate(actors, into = str_c('actor', 
        seq_len(max(str_count(.$actors, ";")) 1)), sep = ";", 
     fill = "right")

-output

> head(out)
    id cowcode location  latitude longitude   asciiname event_date side                actor1 actor2 actor3
1 6040     552   879233 -17.83028  30.98222 Warren Park 2003-06-03    1 opposition supporters   <NA>   <NA>
2 5999     552   882229 -17.85472  30.99000      Rugare 2003-03-18    1                youths   <NA>   <NA>
3 5997     552   882229 -17.85472  30.99000      Rugare 2003-03-18    1 opposition supporters youths   <NA>
4 6238     552   884979 -18.97070  32.67086      Mutare 2003-11-18    1                         <NA>   <NA>
5 8233     552   886763 -20.06373  30.82766    Masvingo 2010-11-07    0    ZANU PF supporters   <NA>   <NA>
6 6956     552   887854 -18.30404  31.19832   Mahusekwa 2008-03-09    0             villagers   <NA>   <NA>
                             issue scope part_violence sec_engagement   numparticipants avg_numparticipants
1     against:Mugabe's repressions     0            NA              2                                    NA
2      against:Mugabe's government     0             1              2                                    NA
3      against:Mugabe's government     0             1              2                                    NA
4 against:Mugabe's autocratic rule     0            NA              2                                    NA
5   for:Mugabe to rule the country     0            NA             NA           300;500                 400
6                       for:Mugabe     0            NA             NA several thousands                2000
                                                                  source version
1                                                   The Associated Press       1
2                                        Agence France Presse -- English       1
3                                        Agence France Presse -- English       1
4                                                   The Associated Press       1
5 BBC Monitoring Africa - Political Supplied by BBC Worldwide Monitoring       1
6                                        Agence France Presse -- English       1
  • Related