Questions tagged [across]

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.

240 questions
0
votes
3 answers

Find variable name and use it to create a new variable name

I need to find the column called "L1_Class" but only using the 'node' object defined first. Then, I'd like to add a column called "L1" that contains the same vector as "L1_Class". All in one short line if possible. library(dplyr) node <- "L1" # (in…
0
votes
1 answer

join problem on image background across two pages

I'm using Indesign to create a multiple pages pdf, I have a background image across two pages, when I export the pdf the background seems not joining well over the two pages even if this image is one unique image.
GGKMNTN
  • 87
  • 9
0
votes
1 answer

case_when using contains instead of declaring each variable to evaluate

I would like to try to avoid stating which variables to assess by instead relying on the suffix _num. mutating a variable conditional on a variable name is possible, but this code needs updating because it should now use across. df %<>%…
ibm
  • 744
  • 7
  • 14
0
votes
1 answer

Updating fct_relevel solution since across took over mutate_at

The solution to piping fct_relevel to mutate a subset of variables no longer works since mutate_at has been deprecated. I'm having a tough time piecing together an updated solution using mutate(across(...), fct_relevel(., ....) , since I get an…
ibm
  • 744
  • 7
  • 14
0
votes
5 answers

Subtract and divide using one mutate_across function in dplyr

I have a data set that looks like the iris data set. Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 …
LDT
  • 2,856
  • 2
  • 15
  • 32
0
votes
2 answers

How do I count the number of unique values across multiple columns in R?

I have a large dataset - 23500 rows. Every row has doublets of events and I need to count the unique events. So I need to count unique events across 30 columns for each row - and create a new column for each row with the count. How to do this the…
0
votes
1 answer

How do i transform a user id into a new identification value, using across/apply function?

I have a variable called user_id in a string format, like: u:fwHX u:fwHX u:fwHX u:h_lx u:x_hi u:x_hi They all start with a "u:" and then followed by a set of letters. I want to transform each unique user_id into a string in the following…
Anja.L
  • 11
  • 2
0
votes
1 answer

Filter dataframe for columns that contain data in R using tidyverse

I am trying to make a simple line of code to detect where there are incorrect entries in a dataframe. Consider the following example: author val1 val2 val3 val4 A 1 B 1 NA A NA NA NA NA NA 2 …
Stevestingray
  • 399
  • 2
  • 12
0
votes
1 answer

Compare within row across multiple columns remove non-matching and create new row

I am trying to count he same addresses and group them by rows. I am reasonably close but have subtle differences across the columns between for the specific address. The aim is to remove any addresses from the row that are not matching and add them…
Benj Young
  • 59
  • 5
0
votes
3 answers

Replace NA values with preexisting value based on multiple conditions

I am working with the following data. It pertains to the dimensions of items and the boxes that they are shipped in. Box_Height Box_Length Box_Width Item_Height Item_Length Item_Width 1 NA 74 4 …
0
votes
1 answer

How to select columns using cur_column and apply function?

I am trying to add columns using rowSums because it is a fast function, using cur_column because the select columns depend on the initial columns a_value b_value. This is a reprex, so it needs to use rowSums cur_column or something similar because…
Alvaro Morales
  • 1,845
  • 3
  • 12
  • 21
0
votes
2 answers

Convert numerical variables into factors when the number of levels is lower than a given threshold with dplyr

I want to convert numerical variables into factors when the number of levels is lower than a given threshold with dplyr. This would be most useful with binary variables coded as numerical '0/1'. example…
GuedesBF
  • 8,409
  • 5
  • 19
  • 37
0
votes
2 answers

apply function across columns using column names within function

I am trying to iterate over 100 columns to identify whether the a variable in a separate column matches the column name. I thought maybe the across function might be able to but can't figure out how to use the mutate on each column. See example…
jsimpsno
  • 448
  • 4
  • 19
0
votes
2 answers

how to programatically apply a transformation to multiple variables and keep the raw and the transformed variables with dplyr for R

I have a large dataset and I would like to apply some transformations in some variables programatically. To illustrate, say I want to apply the log to variables contained in a character vector. I would like to keep the input variables and generate a…
Marcelo Avila
  • 2,314
  • 1
  • 14
  • 22
0
votes
1 answer

Correct syntax for mutate across when excluding columns, part 2

I thought I had the answer to my question here, but when I used with my larger data set I get different results. I suspect the difference is because of the way the na.locf line is acting. Basically I am converting code where I used mutate_at to the…
DaveM
  • 664
  • 6
  • 19
1 2 3
15
16