Questions tagged «tidyr»

5
收集多组列
我有一项在线调查的数据,其中受访者会经历1-3次问题循环。调查软件(Qualtrics)记录在多列,也就是说这个数据,Q3.2的调查将在列Q3.2.1.,Q3.2.2.以及Q3.2.3.: df <- data.frame( id = 1:10, time = as.Date('2009-01-01') + 0:9, Q3.2.1. = rnorm(10, 0, 1), Q3.2.2. = rnorm(10, 0, 1), Q3.2.3. = rnorm(10, 0, 1), Q3.3.1. = rnorm(10, 0, 1), Q3.3.2. = rnorm(10, 0, 1), Q3.3.3. = rnorm(10, 0, 1) ) # Sample data id time Q3.2.1. Q3.2.2. …
107 r  reshape  dplyr  qualtrics  tidyr 

4
dplyr summarise:等效于“ .drop = FALSE”,以在输出中保留长度为零的组
summarise与with plyr的ddply函数一起使用时,默认情况下会删除空类别。您可以通过添加更改此行为.drop = FALSE。但是,当summarise与结合使用时,这是行不通的dplyr。还有另一种方法可以在结果中保留空类别吗? 这是伪造数据的示例。 library(dplyr) df = data.frame(a=rep(1:3,4), b=rep(1:2,6)) # Now add an extra level to df$b that has no corresponding value in df$a df$b = factor(df$b, levels=1:3) # Summarise with plyr, keeping categories with a count of zero plyr::ddply(df, "b", summarise, count_a=length(a), .drop=FALSE) b count_a 1 1 6 …
97 r  dplyr  plyr  tidyr 

2
比较聚集(tidyr)以融化(reshape2)
我喜欢reshape2软件包,因为它使生活变得轻松自如。通常,Hadley在其先前的软件包中进行了改进,以启用简化的,运行速度更快的代码。我想我会给tidyr一抡,并从我读我认为gather是非常相似melt的reshape2。但是在阅读了文档之后,我无法gather完成相同的任务melt。 资料检视 这是数据视图(实际数据以dput帖子结尾的形式显示): teacher yr1.baseline pd yr1.lesson1 yr1.lesson2 yr2.lesson1 yr2.lesson2 yr2.lesson3 1 3 1/13/09 2/5/09 3/6/09 4/27/09 10/7/09 11/18/09 3/4/10 2 7 1/15/09 2/5/09 3/3/09 5/5/09 10/16/09 11/18/09 3/4/10 3 8 1/27/09 2/5/09 3/3/09 4/27/09 10/7/09 11/18/09 3/5/10 码 这是melt我尝试的时尚代码gather。我gather该怎么做melt? library(reshape2); library(dplyr); library(tidyr) dat %>% melt(id=c("teacher", "pd"), value.name="date") dat %>% …
67 r  reshape2  tidyr 

1
如何旋转R中带有节和子节的列组成的数据框
我有一个下面提到的数据框: structure( list(ID = c("P-1", " P-1", "P-1", "P-2", "P-3", "P-4", "P-5", "P-6", "P-7", "P-8"), Date = c("2020-03-16 12:11:33", "2020-03-16 13:16:04", "2020-03-16 06:13:55", "2020-03-16 10:03:43", "2020-03-16 12:37:09", "2020-03-16 06:40:24", "2020-03-16 09:46:45", "2020-03-16 12:07:44", "2020-03-16 14:09:51", "2020-03-16 09:19:23"), Status = c("SA", "SA", "SA", "RE", "RE", "RE", "RE", "XA", "XA", "XA"), Flag …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.