r

Using n() at the same time as calculating other summary statistics

时光总嘲笑我的痴心妄想 提交于 2021-02-20 09:09:33
问题 I am having trouble to prepare a summary table using dplyr based on the data set below: set.seed(1) df <- data.frame(rep(sample(c(2012,2016),10, replace = T)), sample(c('Treat','Control'),10,replace = T), runif(10,0,1), runif(10,0,1), runif(10,0,1)) colnames(df) <- c('Year','Group','V1','V2','V3') I want to calculate the mean, median, standard deviation and count the number of observations by each combination of Year and Group . I have successfully used this code to get mean , median and sd :

Using n() at the same time as calculating other summary statistics

最后都变了- 提交于 2021-02-20 09:08:36
问题 I am having trouble to prepare a summary table using dplyr based on the data set below: set.seed(1) df <- data.frame(rep(sample(c(2012,2016),10, replace = T)), sample(c('Treat','Control'),10,replace = T), runif(10,0,1), runif(10,0,1), runif(10,0,1)) colnames(df) <- c('Year','Group','V1','V2','V3') I want to calculate the mean, median, standard deviation and count the number of observations by each combination of Year and Group . I have successfully used this code to get mean , median and sd :

Using n() at the same time as calculating other summary statistics

爱⌒轻易说出口 提交于 2021-02-20 09:08:35
问题 I am having trouble to prepare a summary table using dplyr based on the data set below: set.seed(1) df <- data.frame(rep(sample(c(2012,2016),10, replace = T)), sample(c('Treat','Control'),10,replace = T), runif(10,0,1), runif(10,0,1), runif(10,0,1)) colnames(df) <- c('Year','Group','V1','V2','V3') I want to calculate the mean, median, standard deviation and count the number of observations by each combination of Year and Group . I have successfully used this code to get mean , median and sd :

R - Handling multiple values as one string in a single variable

不羁的心 提交于 2021-02-20 06:55:48
问题 In a data.frame , I have a categorical variable for the language of a text. But, while most texts are only in one language, some have multiple languages. In my data, they appear in the same column, divided by comas: text = c("Text1", "Text2", "Text3") lang = c("fr", "en", "fr,en") d = data.frame(text, lang) Visually: text lang 1 Text1 fr 2 Text2 en 3 Text3 fr,en I'd like to plot the number of texts in each language, with Text3 being counted both in fr and in en . I found how to split, with: d

R - Handling multiple values as one string in a single variable

我的梦境 提交于 2021-02-20 06:53:28
问题 In a data.frame , I have a categorical variable for the language of a text. But, while most texts are only in one language, some have multiple languages. In my data, they appear in the same column, divided by comas: text = c("Text1", "Text2", "Text3") lang = c("fr", "en", "fr,en") d = data.frame(text, lang) Visually: text lang 1 Text1 fr 2 Text2 en 3 Text3 fr,en I'd like to plot the number of texts in each language, with Text3 being counted both in fr and in en . I found how to split, with: d

ggplot2 issue with facets and turning off clipping

流过昼夜 提交于 2021-02-20 06:24:43
问题 It used to be possible to put text on plot margins by turning off clipping. In ggplot2_2.2.0 this doesn't seem to be possible anymore in plots that use facets (but still works if no facets are used). I've posted an issue here but it has not been addressed yet. Any ideas for workarounds in the meantime would be greatly appreciated! Here is a minimal (non-)working example: library(ggplot2) library(grid) df.plot = data.frame(x = 1, y = 1, facet = 'facet', stringsAsFactors = F) df.text = data

Lubridate not converting datetime to POSIXct correctly in R (dd/mm/yy hh:mm:ss) [closed]

这一生的挚爱 提交于 2021-02-20 05:22:42
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I'm trying to convert my datetime from a csv to POSIXct for data analysis. I've tried multiple codes but either get NA or a wrong format. The code I'm currently using is GRS$datetimelocal<- GRS$`datetime` %>% ymd_hms(tz="UTC") %>% # first convert the `Date and

Lubridate not converting datetime to POSIXct correctly in R (dd/mm/yy hh:mm:ss) [closed]

故事扮演 提交于 2021-02-20 05:22:07
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I'm trying to convert my datetime from a csv to POSIXct for data analysis. I've tried multiple codes but either get NA or a wrong format. The code I'm currently using is GRS$datetimelocal<- GRS$`datetime` %>% ymd_hms(tz="UTC") %>% # first convert the `Date and

Store multiple outputs from each iteration of a for loop

夙愿已清 提交于 2021-02-20 05:18:29
问题 Given a fix path and a very limited directories from year. I'm trying to obtain each combination of path between this initial combination ( fixPath - year ) and the different, non-fixed and non-equally quantity , subdirectories contained in each combination of fixPath - year fixPath <- "C:/Users/calcazar/Desktop/example" year <- 2008:2010 pathVector <- paste(fixPath, year, sep = "/") pathVector [1] "C:/Users/calcazar/Desktop/example/2008" "C:/Users/calcazar/Desktop/example/2009" [3] "C:/Users

Store multiple outputs from each iteration of a for loop

旧巷老猫 提交于 2021-02-20 05:16:14
问题 Given a fix path and a very limited directories from year. I'm trying to obtain each combination of path between this initial combination ( fixPath - year ) and the different, non-fixed and non-equally quantity , subdirectories contained in each combination of fixPath - year fixPath <- "C:/Users/calcazar/Desktop/example" year <- 2008:2010 pathVector <- paste(fixPath, year, sep = "/") pathVector [1] "C:/Users/calcazar/Desktop/example/2008" "C:/Users/calcazar/Desktop/example/2009" [3] "C:/Users