across is a function for use within the Tidyverse set of R packages which is intended to simplify the process of applying functions across columns of a data.frame. Use this tag to ask questions which focus on applying one or more functions to multiple columns with the across function or the rowwise version c_across.
Questions tagged [across]
240 questions
0
votes
1 answer
Scipen option impacting dplyr::across
I was getting a dplyr::across error and I think to R's scipen option is impacting it. I am not sure why this would happen. I do not like seeing scientific notation, so I set this value high, but it seems like it breaks dplyr::across. Any thoughts on…
0
votes
1 answer
Using across() to apply Recode then rescale variables
I would like to first recode a value in a battery of questions and then rescale the results from 0 to 1. I read through here to learn how to apply sequential functions but my results are not rescaled.
var1<-sample(seq(1,11,1), size=100,…

spindoctor
- 1,719
- 1
- 18
- 42
0
votes
2 answers
filtering on multiple columns with multiple conditions
I am working with an administrative data set where I am trying the filter for observations that includes at least one of multiple "diagnosis codes" of interest. The diagnosis codes range from 1-1000, and as an example I want to filter for…

estebancho
- 1
- 1
0
votes
1 answer
How to mutate across a dataframe using dimensions instead of column names?
The following bit of code does a nice job of calculating and outputting the proportions of row totals represented by each element in the dataframe named data:
Output:
# A tibble: 4 x 5
# Rowwise:
To A B C Sum
…

Curious Jorge - user9788072
- 2,548
- 1
- 9
- 22
0
votes
0 answers
How to write custom function that also works with dplyr::across?
I've written some custom functions (see examples below) that work when using both, base R and within a dplyr::mutate pipe. However, I struggle getting it working dynamically with dplyr::across.
What am I doing wrong?
test1 <- function(data,…

deschen
- 10,012
- 3
- 27
- 50
0
votes
1 answer
Creating multiple new columns using mutate() and across() in R
I would like to perform the following calculation on many columns at the same time while they are grouped by ID:
df <- df %>%
group_by(Id) %>%
mutate("Flows.2018.04"= Assets.2018.04 -
(Assets.2018.03 * Returns.2018.04))
The data set…

Kosc0001
- 25
- 5
0
votes
1 answer
Autofill across and above a dynamic range
I'd like to autofill cells across and above a dynamic range.
I have a line of numbers in row 3 and would like to put the word "Customer No." in the cell above each one.
I do this by copying A2 and pasting into C2 then dragging across
Via VBA macro…

Bikat Uprety
- 139
- 8
0
votes
2 answers
Merge survey columns across variables in R
I am analyzing a very large survey in which I want to combine four parts of the survey, through several combinations of 4 questions. Below I have created a small example. A little background: a respondent either answered q2, q5, q8 or q9, because…

Demi
- 33
- 1
- 5
0
votes
2 answers
Apply function on data.frame with mutate across using the same columns from another data.frame
I have two data frames with spectral bands from a satellite, redDF and nirDF. Both data frames have values per date column starting with an 'X', these names correspond in both data frames.
I want to get a new data frame where for each column…

saQuist
- 416
- 7
- 19
0
votes
3 answers
Create columns that extract and flag a detected string pattern from multiple selected columns
I have the below dataframe, where each observation has a string of key and values (k:v)s of different objects. Each object is separated by a \n
df = tribble(
~col, ~summary,
"a", "Oranges: 1\nApples: 1\nPeaches: 6\nBananas: 2",
"b", …

Mohamed Mostafa El-Sayyad
- 257
- 2
- 15
0
votes
0 answers
call dynamic variables created in previous steps inside mutate() + case_when() function
I create a series of dynamically named variables within a function and then want to create new variables based the ones previously created. Specifically, I'm trying to write a function to remove outliers from a series of variables in a data frame.…

kaseyzapatka
- 149
- 2
- 9
0
votes
2 answers
correlation of a vector across all column in R (dplyr)
I have a data frame in R (taken from the dplyr's site here):
library(dplyr)
gdf <-
tibble(g = c(1, 1, 2, 3), v1 = 10:13, v2 = 20:23) %>%
group_by(g)
gdf
Resulting to:
# A tibble: 4 × 3
# Groups: g [3]
g v1 v2
1…

Homer Jay Simpson
- 1,043
- 6
- 19
0
votes
1 answer
Avoid repetition in summarise() using across() or tidyverse
I'm trying to use across() or another tidyverse function to simplify the lines that follow the general line of output.partyA = sum(x.partyA) - sum(y.partyA).
An example of one of the lines that I did to simplify the number of lines was:…
0
votes
2 answers
How to combine multiple variable descriptive stats in one table in R?
I have this code
data_2012 %>%
group_by(job2) %>%
filter(!is.na(job2)) %>%
summarise(mean = mean(persinc2, na.rm = T),
sd = sd(persinc2, na.rm = T))
Which gives me a little table for that specific variable which is perfect,…
0
votes
2 answers
How to: condittional summation in multiple columns in R?
I have a dataset consisting on a first column with dates and many other columns mean daily temperature at different sites (depths in this case). Looks like this:
Date DayMean_2cm DayMean_5cm DayMean_80cm DayMean_120cm DayMean_160cm…

barsoom
- 1
- 1