Questions tagged [spread]

This tag relates to the R spread function. For the javascript spread syntax - please use spread-syntax.

Some of the features are:

  1. Powerful Formula Engine with 300+ Excel Functions
  2. Full Excel Import/Export, PDF, and Print
  3. Support Input, Display, and Data Visualization Controls
  4. Visual Drag-and-Drop Designers
420 questions
0
votes
2 answers

Merging and transforming two sets of data

I have two rather large data files which I need to merge into one, in the following way: A <- tibble( id=1:2, firstName=c("Alice", "Bob") ) B <- tibble( id=c(1,1,2), email=c("alice@wonder.land.com", "alice2@wonderland.com",…
Florian
  • 147
  • 3
  • 7
0
votes
0 answers

How does one spread and calculate percent change across two variables?

I am working with the following dataframe: set.seed(1) my.df <-data.frame(id = gl(3,20,60,labels = c("a","b","c")), year=gl(4,5,60,labels = c("year1","year2","year3","year4")), factor1=gl(5,1,60,labels =…
Fannar
  • 1
  • 2
0
votes
1 answer

Spread data based on multiple key variables

My data: df <- as.data.frame(cbind(Bilagstoptekst = c("A", "A", "A", "B", "B", "C", "D", "E", "E", "F", "F", "F", "F", "F"), AKT=c("80", "80", "80", "80", "80", "25", "80", "80", "80", "80", "80", "25", "25", "80"), …
Louise Sørensen
  • 225
  • 1
  • 11
0
votes
1 answer

Format data long to wide across values with NA

I'm converting an r dataframe from long to wide format, with NA values. And trying to add new rows that perform operations that "skip" the NA values. I can use spread(), but ultimately want to perform operations on each measurement that is…
Matt R
  • 1
  • 1
  • 2
0
votes
0 answers

R spread issue: After adding new updated data, spread() creates a waterfall data frame

I am trying to make a yearly data frame where the input data is updated monthly. It is historic by nature and changes usually occur only in the most recent years. I thought it would be easier to just add the updated information as opposed to…
0
votes
3 answers

Converting features to dummies

I have this matrix: quimio = matrix(c(51,33,16,58,29,13,48,42,30,26,38,16), nrow = 4, ncol = 3) colnames(quimio) = c("Pouca", "Média", "Alta") rownames(quimio) = c("Tipo I", "Tipo II", "Tipo III", "Tipo IV") Which looks like this: …
Pedro Cavalcante
  • 414
  • 4
  • 14
0
votes
0 answers

Spread [tidyr] with one key and multiple value columns

I am trying to use spread as part of the tidyr package. I have one key column (structure_type) and four value columns. (structure_type contains three factor levels.) All the documentation I've seen assumes that spread can only be used for one key…
oatmilkyway
  • 429
  • 1
  • 6
  • 17
0
votes
1 answer

R long to wide format factor levels as binary variables and dates

I want to make a long to a wide format and use the factor Levels as binary variables. This means, if the factor Level is existing at least once, then there should be a 1 in the variable. Otherwise a 0. In addition, I want the dates as variable…
jaskrimi
  • 17
  • 4
0
votes
1 answer

Spread by Two Columns

I am trying to spread a data frame, but I am not quite familiar with spread() and gather(). Below is a sample of my data. It has 9 rows all with the same Application.Number. I would like to end up with one row per Application.Number-Decicion…
DGenchev
  • 327
  • 3
  • 12
0
votes
2 answers

Reshaping data with tidyr

I have data in the format: sample height width weight 1 a h1 w1 p1 2 a h2 w2 p2 3 b h3 w3 p3 4 b h4 w4 p4 where h1 and h2 are replicate measurements for the height of…
user10577351
  • 67
  • 1
  • 5
0
votes
0 answers

R - spread & add rows

I have long dataframe with this kind of data. df <- read.table(text=" category month 1 1 2016-12 2 1 2016-12 3 1 2017-01 4 5 2016-11 5 5 …
Sklenicka
  • 595
  • 2
  • 4
  • 16
0
votes
0 answers

Why is the spread function in R adding NAs to my grouped and summarised dataframe?

I'm applying the spread function from the tidyr package to a grouped dataset. Below is an example of my actual data. I can summarize the data using group_by and the summarise function in dplyr, which yields a small dataframe with no NAs. However, if…
0
votes
1 answer

how to convert different levels in one row

I have a set of data like below: BETA_LACT R I S - 23 25 91 - 30 0 109 - 0 0 136 + 73 0 0 + 14 0 59 + 0 0 49 I want to convert the data to the format below: R_- I_- S_- R_+ I_+ S_+ 23 25 91 73 0 0 30 0 …
0
votes
1 answer

spread for duplicate identifiers

I'm really sorry to ask this question again, because there are already many questions about this. However, none of the solutions worked for my problem. My data looks like this: id scale rater rating 1 A 1 5 1 B 1 7 1 A …
Akoasma
  • 11
  • 5
0
votes
1 answer

dplyr::spread for multiple columns using purrr::map

I want to get dplyr::spread for multiple columns using purrr::mapinto list of data.frames. Wonder how to achieve the desired result? library(tidyverse) mtcars %>% dplyr::group_by(gear, carb) %>% dplyr::summarise_at( .vars = names(.)[1:9] …
MYaseen208
  • 22,666
  • 37
  • 165
  • 309