\$\begingroup\$
\$\endgroup\$
1
I have a data frame called data
with lots of columns, and Country
is one of them.
I created a new logical column called train
, which is true when the row belongs to the train set and false otherwise. The data frame is already sampled.
Now I want to be sure that there are no countries in both train and test sets with this code:
nrow( data[ data[ data$train, ]$Country %in% data[! data$train, ]$Country, ] ) == 0
which evaluates to true
, so I guess I sampled correctly. But that line makes my eyes bleed.
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
1 Answer 1
\$\begingroup\$
\$\endgroup\$
I would do:
with(data, length(intersect(Country[train], Country[!train])) == 0)
answered Oct 16, 2013 at 0:30
lang-r
data
is also the name of a function in the coreutils
package, it is not good practice to use it for the name of an object. \$\endgroup\$