Reputation: 1017
I have the following code that identifies which variables from two columns in dataframe 'prep' are not in a certain column of dataframe 'results':
unique(c(as.character(prep$player1), as.character (prep$player2))) [!unique(c(as.character(prep$player1), as.character (prep$player2)))%in% results$names]
It works well when it is on one line. But I want it to run at least over two lines to make it easier to see it. I tried
unique(c(as.character(prep$player1), as.character (prep$player2)))+
[!unique(c(as.character(prep$player1), as.character (prep$player2)))%in% results$names]
and
unique(c(as.character(prep$player1), as.character (prep$player2)))
+[!unique(c(as.character(prep$player1), as.character (prep$player2)))%in% results$names]
I get the error: unexpected '['
in "[" and unexpected '[' in "+["
Can you help me break the code. Thanks
Upvotes: 1
Views: 642
Reputation: 887048
If we want to run iin multiple lines, use, just split after the [
(also the +
may be the artifact from copying the code from console)
unique(c(as.character(prep$player1), as.character (prep$player2)))[
!unique(c(as.character(prep$player1),
as.character (prep$player2)))%in% results$names]
In R 4.1.0
, we can also use |>
for chaining
unique(c(as.character(prep$player1), as.character (prep$player2))) |>
{\(dt) dt[!unique(c(as.character(prep$player1),
as.character (prep$player2)))%in% results$names]}()
Upvotes: 1