R/p_cor.r

Defines functions p_cor

Documented in p_cor

#' Finds correlation coefficients, with support for piping
#' 
#' A wrapper function for `cor()`, with support for piping.
#'
#' @param data the data
#' @param x one of the two variables
#' @param y one of the two variables
#' @param ... additional arguments passed to [stats::cor()].
#'
#' @returns a numeric object
#' @export
#'
#' @examples
#' # load the data
#' data(nhanes)
#' 
#' # get correlation coefficient for systolic and diastolic
#' nhanes |> p_cor(bpxosy1,bpxodi1,use='complete.obs')
p_cor<-function(data,x,y,...){
  x_string<-deparse(substitute(x))
  y_string<-deparse(substitute(y))
  stats::cor(data[,x_string],data[,y_string],...)
}

Try the baseverse package in your browser

Any scripts or data that you put into this service are public.

baseverse documentation built on April 29, 2026, 1:08 a.m.