File: matchDataFrameSubset.R

package info (click to toggle)
r-cran-bbmisc 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,256 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# FIXME: not used anywhere?
matchDataFrameSubset = function(df, ss, factors.as.chars = TRUE) {
  # checkArg(df, c("list", "data.frame"))
  # checkArg(ss, c("list", "data.frame"))
  if (!isProperlyNamed(df))
    stop("'df' is not proberbly named")
  if (!isProperlyNamed(ss))
    stop("'ss' is not proberbly named")
  if (any(names(ss) %nin% names(df)))
    stop("Names of 'ss' not found in 'df'")
  if (is.list(df))
    df = as.data.frame(df, stringsAsFactors = FALSE)
  if (is.list(ss))
    ss = as.data.frame(ss, stringsAsFactors = FALSE)

  df = subset(df, select = names(ss))

  if (factors.as.chars) {
    df = convertDataFrameCols(df, factors.as.char = TRUE)
    ss = convertDataFrameCols(ss, factors.as.char = TRUE)
  }

  conv = function(x) rawToChar(serialize(x, connection = NULL, ascii = TRUE))
  match(rowSapply(ss, conv, use.names = FALSE), rowSapply(df, conv, use.names = FALSE))
}