Skip to content

map a custom function with two input columns within summarize or mutate #189

Answered by markfairbanks
JP-Solomon asked this question in Q&A
Discussion options

You must be logged in to vote

In a general sense - yes, you can create a custom function that you can input two columns into. There are some specific functions that aren't implemented in polars or tidypolars that you use (like lm()) that limits recreating your exact example.

You're also using a tibble/data frame as an input to your function in your example which isn't how you would do it in polars/tidypolars. You would actually want to input columns. So in R your function would look like this:

library(tidyverse)
#function definition
get_spec = function(time, original){
  original = resid(lm(original~time))
  original = original-median(original)
  original = original/mad(original,center=0)
  return(original)
}

#apply …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@JP-Solomon
Comment options

Answer selected by JP-Solomon
Comment options

You must be logged in to vote
1 reply
@markfairbanks
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants