dcast

Reshape data from long to wide format - more than one variable [duplicate]

落花浮王杯 提交于 2019-11-28 06:47:13
问题 This question already has an answer here: Reshape multiple values at once 2 answers I’m trying to reshape my data from long to wide formula using the dcast function from reshape2. The objective is to use different variables in the value.var parameter but R doesn't let me use more than one value in it. Is there any other way I could fix it? I've looked at other similar questions but I haven't been able to find a similar examples. Here is my current dataset: +---------+------+--------+---------

Spread with duplicate identifiers (using tidyverse and %>%) [duplicate]

淺唱寂寞╮ 提交于 2019-11-27 04:53:34
This question already has an answer here: Reshaping data in R with “login” “logout” times 5 answers My data looks like this: I am trying to make it look like this: I would like to do this in tidyverse using %>%-chaining. df <- structure(list(id = c(2L, 2L, 4L, 5L, 5L, 5L, 5L), start_end = structure(c(2L, 1L, 2L, 2L, 1L, 2L, 1L), .Label = c("end", "start"), class = "factor"), date = structure(c(6L, 7L, 3L, 8L, 9L, 10L, 11L), .Label = c("1979-01-03", "1979-06-21", "1979-07-18", "1989-09-12", "1991-01-04", "1994-05-01", "1996-11-04", "2005-02-01", "2009-09-17", "2010-10-01", "2012-10-06" ), class

Means multiple columns by multiple groups

不羁的心 提交于 2019-11-26 21:54:15
问题 I am trying to find the means, not including NAs, for multiple columns withing a dataframe by multiple groups airquality <- data.frame(City = c("CityA", "CityA","CityA", "CityB","CityB","CityB", "CityC", "CityC"), year = c("1990", "2000", "2010", "1990", "2000", "2010", "2000", "2010"), month = c("June", "July", "August", "June", "July", "August", "June", "August"), PM10 = c(runif(3), rnorm(5)), PM25 = c(runif(3), rnorm(5)), Ozone = c(runif(3), rnorm(5)), CO2 = c(runif(3), rnorm(5)))

Spread with duplicate identifiers (using tidyverse and %>%) [duplicate]

ぐ巨炮叔叔 提交于 2019-11-26 11:18:27
问题 This question already has answers here : Reshaping data in R with “login” “logout” times (6 answers) Closed 2 years ago . My data looks like this: I am trying to make it look like this: I would like to do this in tidyverse using %>%-chaining. df <- structure(list(id = c(2L, 2L, 4L, 5L, 5L, 5L, 5L), start_end = structure(c(2L, 1L, 2L, 2L, 1L, 2L, 1L), .Label = c(\"end\", \"start\"), class = \"factor\"), date = structure(c(6L, 7L, 3L, 8L, 9L, 10L, 11L), .Label = c(\"1979-01-03\", \"1979-06-21\"