Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unexpected Special in %:%" %do% foreach, yet the syntax is correct and the foreach package has been loaded

Tags:

r

foreach(i = 1:nrow(teamAttributes))
%:% foreach(j = 1:nrow(allTeams))
%do% if (teamAttributes$team_api_id[i] == allTeams$home_team_api_id[j]) {
subjectTeamAttributes <- rbind(teamAttributes[i, ], subjectTeamAttributes)
}

##Error Messages

Error: unexpected SPECIAL in "%:%"
Error: unexpected SPECIAL in "%do%"
subjectTeamAttributes <- rbind(teamAttributes[i, ], subjectTeamAttributes)
Error in `[.data.frame`(teamAttributes, i, ) : object 'i' not found
like image 907
inly Avatar asked Sep 19 '25 14:09

inly


2 Answers

All pipes should be at the end of the previous line and not at the start of the second line. Please insert %do% at the end of lines 1 and 2

like image 188
Jerin Mathew Avatar answered Sep 21 '25 05:09

Jerin Mathew


Answered by Dason above. THe format was the issue. Putting it all on one line solved the issue.

like image 32
inly Avatar answered Sep 21 '25 04:09

inly