This question is in part an R issue, but primarily an across issue.
Consider this code:
x <- tibble(x = rpois(1e2, 5), z = rnorm(1e2, 0, 1))
x %>% dplyr::mutate(across(where(is.numeric), round, 4))
My goal is to round the numeric columns, but not the integer columns, which of course need no rounding. The problem from an R perspective is that integer columns are numeric columns also. But this code further results in the integers being converted to numeric (albeit still being nominal integers in output), which is undesirable. I want the non-integer columns rounded and the integer columns left alone.
The goal is to specify an across statement that works for is.numeric but also enforces !is.integer.
This doesn't work, and other variants I have tried (enclosing the conditions in c() or moving the parentheses around) haven't seemed to work either.
Any suggestions for (1) the best way to incorporate multiple conditions with where, and (2) while we are at it, how to operate on numeric vectors while carving out integer vectors from that same operation? The colwise vignette did not seem to address multiple conditions with where.
Actually, you are correct, it does work on the example.
It was not working for me on my actual data set and I assumed it would not work on the example either.
But, it looks like the reason is because I had an additional column in the actual data set with a date in it (class dttm). Then, it fails. So, I suppose if I may extend this, add a column for y=Sys.time(), and we once again need to do something else, unfortunately.
interestingly, when a date is a column in the dataset, the earlier anonymous function query suggested above still works. Perhaps it is just more robust in some ways?
I see your point. I see while anonymous works, the other one does not. I think, both are equivalent. But they are not. One interesting thing, I notice, date-time object is not numeric or integer but double !!! (see following code). That might be the reason behind they are not same.