selectRows | R Documentation |
Select rows from a data frame according to reference IDs
selectRows(x, ref, by = NULL)
x |
a data frame to select |
ref |
reference IDs, by which the data frame x is to be filtered. |
by |
the column name (or NULL meaning "row names"), by which the selection is operated on. |
a data frame filtered and ordered by ref
on by
column.
The result of thi function is similar to subset
function. The
difference is that subset
function maintains the row orders
in the data frame x
, but selectRows
maintains
the order or ref
. selectRows
does not work if there are
duplicates in both "ref" and "by" pointed column.
{
## Not run:
### Unduplicated "by"
x = data.frame(V1 = letters[1:15], b = rnorm(15))
# Unduplicated "ref"
selectRows(x, ref = c(19, "a", "d", "c", "b"), by = "V1")
# Duplicated "ref"
selectRows(x, ref = c(19, "a", "a", "c", "b"), by = "V1")
ref1 = sample(1:20, 8)
print(ref1)
selectRows(x, ref = ref1)
### Duplicated "by"
x = data.frame(V1 = rep(letters[1:5], 1:5), b = rnorm(15))
# Unduplicated "ref"
# debugonce(selectRows)
selectRows(x, ref = c(19, "a", "d", "c", "b"), by = "V1")
# Duplicated "ref" (ERROR!)
selectRows(x, ref = c(19, "a", "a", "c", "b"), by = "V1")
## End(Not run)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.