Skip to main content

All Questions

Tagged with
1 vote
1 answer
24 views

Long to wide format based on variable suffixes in tidyverse in R

I wonder if there is a way for my DATA to be reformatted to my Desired_output below? Specifically, for each unique study, we stick together a pair of pre and postNUMBER together, separately for T and ...
Simon Harmel's user avatar
  • 1,449
2 votes
2 answers
30 views

Wide format data by pasting two sets of variables into one in R

I've tried to wide-format my DATA into my Desired_output using: pivot_wider(DATA, names_from = Year, values_from = c(Type, Language)) without success. Is there a way to achieve my Desired_output? ...
Simon Harmel's user avatar
  • 1,449
1 vote
1 answer
25 views

How to merge two columns when long-formatting data frame in R

Below, I'm can use tidyr::pivot_longer(DATA, -InstNm, names_sep = "_", names_to = c("Indicator", ".value")) to get very close to my Desired_output. But I wonder how I can ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
26 views

Long-formatting several sets of similarly named of variables in an R data.frame

I have several sets of columns whose names are related. For example, in the toy DATA below, one set of variables start with OTE_ and another set of variables start with RAE_. In my actual data, I have ...
Simon Harmel's user avatar
  • 1,449
0 votes
2 answers
62 views

Reformatting a dataframe into wide format in R

I was wonder if there is a way for my DATA to be reformatted to my Desired_output below? Specifically, for each unique study, we stick together a pair of pre and postNUMBER together, separately for t ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
32 views

Replace wrong values in a dataframe using a dataframe of correct values [duplicate]

In my DATA below, some Names are misspelled. I've determined the Unique_Names and correspondingly created the Correct_Unique_Names for those unique names. But I wonder how to insert my ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
38 views

Creating a function to modify a list of variables conditionally using the case_when function in R [duplicate]

I would like to create several (30+) variables based on the following function where N, B, C, Q are each a list of variables within the df dataframe. I've included the code as well as the error from R ...
Jeremy B's user avatar
1 vote
1 answer
71 views

Using quotation marks in an R function

I am trying to write an R function which returns a table of summary statistics (based on the get_summary statsfunction from the rstatix package) and computes a Wilcoxon test. This would be performed ...
user23485480's user avatar
-1 votes
1 answer
80 views

Remove elements of a named list based on the naming match in R

Please note: this question is completely different from a previous question. In My_list below, I wonder how to eliminate whole elements whose names' prefix "Gain" has a different number ...
Simon Harmel's user avatar
  • 1,449
1 vote
2 answers
58 views

subtract all unique pairs of elements of a list in R

In My_list below, I want to subtract all unique pairs of elements (no repetition) from one another. In this example, because there are 3 elements in My_list, therefore, we expect choose(3, 2)= three ...
Simon Harmel's user avatar
  • 1,449
1 vote
1 answer
46 views

Create a named list of numerics from a data.frame in R

I want to create a named list of numerics from my DATA, such that all Variables ending in baseline get subtracted from their corresponding Variables ending in post1. For example, the first element's ...
Simon Harmel's user avatar
  • 1,449
1 vote
2 answers
66 views

Paste the names of a columns in which there is a "Y" in R

In my DATA below, I want to create a New_Column which pastes the names of columns A:F in which there is a Y to achieve my Desired_Output. I was wondering if this might be possible in R? DATA <- ...
Simon Harmel's user avatar
  • 1,449
3 votes
4 answers
100 views

reading text as a dataframe into R

In my DATA below, read.table() requires study column to not have any white spaces between its elements. For example, if an element is "Hayati & Jalilifar", then read.table() throws an ...
Simon Harmel's user avatar
  • 1,449
0 votes
1 answer
37 views

Building custom function with tidyverse in R - can't make the enquo() work

I have a data frame with predictions and observed values and they come from various datasets so, something like: datasets = rep(1:4, each=5) obs = runif(n=20, min=1, max=20) pred = runif(n=20, min=1, ...
Jonathan's user avatar
  • 165
2 votes
1 answer
112 views

Complete time.series using a function based on data.table

I'm trying to learn more about data.table and the proper way to use it. Reproducible example This is my data: set.seed(1) df <- data.frame(group1 = rep(c("a", "b"), each = 9), ...
Edo's user avatar
  • 7,698

15 30 50 per page
1
2 3 4 5
15