Re: [R] writing a function to work with dplyr::mutate()

2021-01-20 Thread Steven Rigatti
This works perfectly. Ah, just needed a vector as output instead of a 1-column df. Thank you!!! On Tue, Jan 19, 2021 at 2:18 PM Bill Dunlap wrote: > Your translate... function seems unnecessarily complicated and reusing the > name 'var' for both the input and the data.frame containing the input

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Jeff Newmiller
I avoid case_when, so don't complain to me about it. Bert and I both suggested standard evaluation approaches that are very amenable to using lookup tables. On January 19, 2021 1:51:17 PM PST, Steven Rigatti wrote: >I use case_when a lot - but I have a lot of dynamic tables to treat >this >way a

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread John Kane
David library(tidyverse) char_vec <- sample(c("a", "b", "c"), 10, replace = TRUE) recode(char_vec, a = "Apple") works for me. On Tue, 19 Jan 2021 at 15:13, David Winsemius wrote: > > On 1/19/21 11:17 AM, Bill Dunlap wrote: > > Your translate... function seems unnecessarily complicated and reusi

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread David Winsemius
Sent from my iPhone > On Jan 19, 2021, at 1:52 PM, Steven Rigatti wrote: > > I use case_when a lot - but I have a lot of dynamic tables to treat this > way and case_when has to be hard-coded. But, but, but my case_when-based illustration let you pass a parameter dataframe that contain

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Steven Rigatti
I use case_when a lot - but I have a lot of dynamic tables to treat this way and case_when has to be hard-coded. On Tue, Jan 19, 2021 at 3:48 PM Jeff Newmiller wrote: > Second this. There is also the findInterval function, which omits the > factor attributes and just returns integers that can be

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Jeff Newmiller
Second this. There is also the findInterval function, which omits the factor attributes and just returns integers that can be used in lookup tables. On January 19, 2021 10:33:59 AM PST, Bert Gunter wrote: >If you are willing to entertain another approach, have a look at ?cut. >By >defining the '

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread David Winsemius
On 1/19/21 11:17 AM, Bill Dunlap wrote: Your translate... function seems unnecessarily complicated and reusing the name 'var' for both the input and the data.frame containing the input makes it confusing to me. The following replacement, f, uses your algorithm but I think gets the answer you w

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Bill Dunlap
Your translate... function seems unnecessarily complicated and reusing the name 'var' for both the input and the data.frame containing the input makes it confusing to me. The following replacement, f, uses your algorithm but I think gets the answer you want. f <- function(var, upper, lookup) {

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Steven Rigatti
It's not that I can't get the output I want. I was able to do that. It is just that I can't make it pipeable - I get that weird error message that I don't understand. On Tue, Jan 19, 2021 at 1:34 PM Bert Gunter wrote: > If you are willing to entertain another approach, have a look at ?cut. By >

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread David Winsemius
On 1/19/21 7:50 AM, Steven Rigatti wrote: I am having some problems with what seems like a pretty simple issue. I have some data where I want to convert numbers. Specifically, this is cancer data and the size of tumors is encoded using millimeter measurements. However, if the actual measurement

Re: [R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Bert Gunter
If you are willing to entertain another approach, have a look at ?cut. By defining the 'breaks' argument appropriately, you can easily create a factor that tells you which values should be looked up and which accepted as is. If I understand correctly, this seems to be what you want. If I have not,

[R] writing a function to work with dplyr::mutate()

2021-01-19 Thread Steven Rigatti
I am having some problems with what seems like a pretty simple issue. I have some data where I want to convert numbers. Specifically, this is cancer data and the size of tumors is encoded using millimeter measurements. However, if the actual measurement is not available the coding may imply a less