reshape2

Running multiple simple linear regressions from a nested dataframe/tibble

不问归期 提交于 2021-01-28 04:26:50
问题 I am trying to run multiple simple linear regressions based on data from a nested data frame and store the regression fit coefficients in a dataframe using tidy(). My code block is as follows library(tidyverse) library(broom) library(reshape2) library(dplyr) Factors <- as.factor(c("A","B","C","D")) set.seed(5) DF <- data.frame(Factors, X = rnorm(4), Y = rnorm(4), Z= rnorm(4)) MDF <- melt(DF, id.vars=c("Factors","X")) DFF <- MDF %>% nest(-Factors) If it is a single dataframe with many columns,

Running multiple simple linear regressions from a nested dataframe/tibble

折月煮酒 提交于 2021-01-27 22:50:47
问题 I am trying to run multiple simple linear regressions based on data from a nested data frame and store the regression fit coefficients in a dataframe using tidy(). My code block is as follows library(tidyverse) library(broom) library(reshape2) library(dplyr) Factors <- as.factor(c("A","B","C","D")) set.seed(5) DF <- data.frame(Factors, X = rnorm(4), Y = rnorm(4), Z= rnorm(4)) MDF <- melt(DF, id.vars=c("Factors","X")) DFF <- MDF %>% nest(-Factors) If it is a single dataframe with many columns,

In R, using melt(), how can I hide warning messages?

隐身守侯 提交于 2020-12-26 06:54:24
问题 I'm melting some data and don't want to provide an id.var parameter to melt. The data melts fine, but I get the "No id variables; using all as measure variables" Is there a way to prevent that message from coming up, or a way to say id.var=default or something like that? An iris example using dplyr: > dt <- iris %>% summarize_at(c("Sepal.Length","Sepal.Width"), funs(mean)) > dt Sepal.Length Sepal.Width 1 5.843333 3.057333 > melt(dt, value.name="Mean") No id variables; using all as measure

Wide to long: multiple columns, two timepoints, two groups

别说谁变了你拦得住时间么 提交于 2020-07-18 08:06:09
问题 I have searched and found a number of examples, so far I have not been able to solve a problem in transforming my data from wide to long. Below is an example of the data: set.seed(12345) id = 1:100 age = sample(1:100, 100, replace=TRUE) group = sample(1:2, 100, replace=TRUE) t0_var1 = sample(1:300, 100, replace=TRUE) t2_var1 = sample(1:300, 100, replace=TRUE) t0_var2 = sample(1:600, 100, replace=TRUE) t2_var2 = sample(1:600, 100, replace=TRUE) t0_var3 = sample(1:700, 100, replace=TRUE) t2

Reshape Table in MySQL or R [duplicate]

允我心安 提交于 2020-03-20 07:57:16
问题 This question already has answers here : How to reshape data from long to wide format (11 answers) Closed 2 years ago . I have the following table: perid date rating 10001 2005 RD 10001 2006 GN 10001 2007 GD 10002 2008 GD 10002 2009 YW 10002 2010 GN 10002 2011 GN 10003 2005 GD 10003 2006 GN 10003 2007 YW how can I turn this table to the following format: perid 2005 2006 2007 2008 2009 2010 2011 10001 RD GN GN N/A N/A N/A N/A 10002 N/A N/A N/A GD YW GN GN 10003 GD GN YW N/A N/A N/A N/A Or if I

How do I cast data into non-equi columns?

谁说胖子不能爱 提交于 2020-02-24 12:37:06
问题 I have a dataset of events, grouped by let like so: set.seed(3) events <- data.frame( let = rep(LETTERS[1:2], each=3), age = c(0,sample(1:20, size=2), 0,sample(1:20, size=2)), value = sample(1:100, size=6)) let age value 1 A 0 61 2 A 4 60 3 A 16 13 4 B 0 29 5 B 8 56 6 B 7 99 How can I cast the data frame so that age is multiple columns grouped into weeks? So for each column, take the value of the largest age that is less than or equal to 0, 7, 14, 21 days. events.cast <- data.frame( let =

Pivot by group for unequal data size

◇◆丶佛笑我妖孽 提交于 2020-02-05 05:13:27
问题 I have the following DF: DF = structure(list(ID = c(21785L, 21785L, 21785L), V1 = c(0.828273303, 6.404590021, 0.775568448), V2 = c(2L, 3L, 2L), V3 = c(NA, 1.122899914, 0.850113234), V4 = c(NA, 4L, 3L), V5 = c(NA, 0.866757168, 0.868943246 ), V6 = c(NA, 5L, 4L), V7 = c(NA, 0.563804788, 0.728656328), V8 = c(NA, 6L, 5L), V9 = c(NA, 0.888109208, 0.823803733), V10 = c(NA, 7L, 6L), V11 = c(NA, 0.578834113, 0.863467391 ), V12 = c(NA, 1L, 7L), V13 = c(NA, NA, 0.939920869)), class = "data.frame", row