All Questions
364
questions
3
votes
1
answer
67
views
Why do I get different outputs for calling "replicate" with and without pipe "%>%" in R?
I want to generate a character vector with 20 elements, each has a random string.
So I generate a random string with the following code:
sample(x = c(letters, LETTERS), size = sample.int(100, 1), ...
1
vote
4
answers
54
views
define condition while piping a tibble
Is there any way to define a condition so as I can use it several time while piping a tibble?
data <- tibble(age = c(25, 30, 18, 40), income = c(50000, 70000, 35000, 80000))
filter_condition <- ...
0
votes
1
answer
35
views
Merge dataframes with unequal lengths and substituting 0 for values that are not present [duplicate]
I have two data frames of unequal length, one data frame contains a subset of dates of the first data frame and they each have different columns:
Data Frame 1:
structure(list(date = structure(c(19241, ...
1
vote
0
answers
41
views
Using C# System.Diagnostics to launch R to process information and pass results back to console
I have a legacy C# application that uses datatables in its operations.
I need to pass information from a datatable in a C# program to R; then get R to process the data using the instructions from a ...
1
vote
2
answers
35
views
Generate new variable using reference to cell within pipe
I am trying to add a new column to a dataframe, with values coming from a specific cell of the same df. I want to do this within a pipe, without referring explicitely to the original dataframe.
In the ...
17
votes
7
answers
2k
views
How can I run a function at the end of a pipe?
This code makes a sentence from two different columns in a data frame
library(dplyr); library(tibble); library(magrittr)
mtcars %>%
rownames_to_column(var = "car") %>%
sample_n(5)...
0
votes
3
answers
80
views
R piping: object not found. What am I missing?
So this is really a basic question, however I am stuck with trying to use the following basic code:
dc_test |> table(testVar)
It leads to:
Error: Object 'testVar' not found
dc_test is a data....
1
vote
1
answer
71
views
How do I summarize data and bind new rows to an existing data frame?
Edited to give reprex in response to comments.
I'm reading in several years of public temperature data for California's 58 counties. I'd like to create a summary, the daily statewide average, and put ...
0
votes
1
answer
76
views
purrr::set_names using pipe operator in R
How do I edit the below R pipe so that I can change the column names before reading all the sheets into a single dataframe?
Currently, the set_names function is applied to sheet names in the Excel, ...
0
votes
1
answer
27
views
Create a column with one of two variables based on another columns character
I have a dataframe that looks like this:
location
sample_year
mean
Ann Lake
2003
22
Bird Lake
2003
22
Tree Lake
2003
22
Ann River
2003
22
Tim River
2003
22
Dog River
2003
22
Apple River
2003
...
0
votes
0
answers
56
views
R's new native pipe does not work How to solve? [duplicate]
This is my reproducible sample data
df1 <- structure(list(No = 1:3, A = c(1L, 0L, 0L), B = c(0L, 1L, 0L),
C = c(1L, 2L, 1L), D = c(0L, 1L, 0L)), class = "data.frame",...
1
vote
1
answer
110
views
Why can very long pipe (%>%) statements cause "Error: C stack usage is too close to the limit"?
Before I start:
I'm aware that there are quite a few threads on this error "out there" but none of them seem to narrow the problem down to very long pipe statements specifically.
By chance I ...
0
votes
1
answer
58
views
how to refer to local and upper level LHS
In the following, is there a way to refer to both expr1 and expr2 in the expr?
expr1 %>% {
expr2 %>% expr
}
For example, this doesn’t work
mtcars %>% {
mtcars[1:3] %>% mutate(disp2 = ...
1
vote
1
answer
67
views
avoiding/disabling lazy evaluation for pipeline processing [duplicate]
Imagine I have a set of functions for data processing, for example:
procA <- function(input){
cat('\n Now processing #A') # message just to log pipeline flow
# Actual data processing, may ...
0
votes
2
answers
97
views
Is there a base pipe way of using the unique value of a column to pipe into labs from ggplot
The problem is fairly simple - if I take a df and perform a few filtering steps on it, I'd like to be able to pipe the output of those into a ggplot function and use the unique value of a particular ...