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
0 answers
How to (concisely) fill in only the missing values/cells in a data frame by joining tables
My problem: I had missing values in a data frame (original_df). After a while I received new data for the original observations for some columns (new_df). I wanted to update the original_df accordingly. Data that wasn't missing priorly should be…

c_dinosaur
- 3
- 2
0
votes
1 answer
How to differentiate between interval and numeric columns in dplyr::across()?
I have a tibble containing Intervals, created with lubridate.
library(tidyverse)
Interval=lubridate::interval(POSIXct(1)+1,POSIXct(1))
numeric=3
character="A"
tbl<-tibble(Interval,numeric,character)
with the title reflecting the class of the data…

Joost Keuskamp
- 125
- 1
- 9
0
votes
1 answer
Reading multiple lines from a List with one iteration
When reading a CSV file, I want to remember/store data across multiple rows of that particular file, e.g. to make an object based on columns from line 1+2, line 3+4, etc.
While I've found a solution, I do believe there should a 'cleaner' solution…

kdh
- 1
- 1
0
votes
1 answer
Loop to recode variables using dplyr mutate recode
I am new to R, and I have been using Stata for multiple years. I am trying to create a loop and a set of conditions within the loop that will do some recoding of data. I am, truly, lost, so any suggestions are welcomed. Please,…

George
- 95
- 7
0
votes
1 answer
R Create Multiple New Variables
I'm having trouble finding a solution for a complex variable assignment need. I need to create new variables based on the values in existing variables, but I need to do the same new variable creation many times using a different set of existing…

lemnbalm
- 5
- 3
0
votes
1 answer
Calculating differences in daily averages between rows with similar strings, and across multiple duos of strings?
I have a dataframe with daily averages of temperature values from June-August across different sites. The numbers across the top of my dataframe are the day of the month. Here is what my dataframe:
df = structure(list(month = c("Jun", "Jun", "Jun",…

Kristen Cyr
- 629
- 5
- 16
0
votes
1 answer
tidyverse across where(!is.factor)?
I would like to create factor variables for all non-factor columns. I tried:
dat %>%
mutate(across(where(!is.factor), as.factor, .names = "{.col}_factor"))
But get error message:
Error in `mutate()`:
! Problem while computing `..1 =…

Shira
- 119
- 5
0
votes
1 answer
when dplyr/accross function use for data.table, the speed is slow
Using dplyr/accross is very easy to summarize numeric variables which group by character variables (no need input variable names).
Across can use to data.table but the speed will slow (just as manipulate dataframe ) .
Is the any way for not lost…

anderwyang
- 1,801
- 4
- 18
0
votes
1 answer
Group by multiple non-numeric columns in dplyr
I am trying to group_by multiple, only non-numeric columns, in dplyr. The aim is then to create two columns with the percentage and absolute changes.
Right now, I can achieve this by listing all non-numeric column names by hand, and then…

Ingrid
- 27
- 6
0
votes
0 answers
Using cur_column() with mutate(across(all_of())) - Recursive Error
My goal is to take a subset of columns (COL_NAMES) within a dataframe (LR_DATA) and apply a function (FUNCTION). The dataframe (LR_DATA) is mostly nested vectors except for one identifying column (var1). However, I cannot seem to correctly pass the…

moo5003
- 19
- 4
0
votes
1 answer
Is this possible to change a single column in `dplyr` without reusing its name and without `across`?
Is this possible to change a single column in dplyr without reusing its name and without across ?
library(dplyr)
# The two following methods works
mtcars %>%
mutate(cyl = cyl * 2)
# Drawback : the name of the column is repeated
mtcars %>%
…

Julien
- 1,613
- 1
- 10
- 26
0
votes
1 answer
summarise_each() with across() for dplyr package
I have this script, I want to know how I can replace summarise_each() with the across() function?
common_bw_elements = df %>%
group_by(range_of_commons = cut(common_IDs,
breaks= c(-Inf,0, 5, 10, 20, 30, 60, 100, 200, 300, 600, 1200, 1800,…

Sandy
- 1,100
- 10
- 18
0
votes
1 answer
Set factor values for multiple columns to missing without losing the label attribute
I have surveydata with a number of likert-scale items that have been imported as factors where the actual question is attached to those factors as the "label" attribute.
In addition, there is one random variable that has been assigned to each…

Rasul89
- 588
- 2
- 5
- 14
0
votes
0 answers
CRAN R - Assign the value '1' to many dummy variables at once
I have the following (sample) dput() for a dataframe consisting of non-unique IDs, countries, and columns representing country names:
structure(list(id = c(1, 1, 2, 3, 4, 4), country = c("USA", "Japan",
"Germany", "Austria", "Japan", "Austria"),…

ZZ Top
- 93
- 5
0
votes
1 answer
Problem converting columns from character to factor using across within mutate
I am encountering a problem when I run the following code to try to convert several columns of data from character to factor:
library(readxl)
library(dplyr)
"LR_df1"<-read_excel("Correct file location.xlsx",sheet="Correct sheet")
LR_df1 %>%
…

donm79
- 31
- 1
- 3