tidyverse

r mutate_each function is deprecated

送分小仙女□ 提交于 2020-01-04 02:03:18
问题 I use the function mutate_each from the tidyverse package and I get a message this function is deprecated. I would like to use the other functions that are not deprecated to change field types. Below is a reproducible example of how I currently employ mutate_each. library(tidyverse) set.seed(123) df <- data.frame(FirstName = sample(LETTERS[1:2],size=3, replace=TRUE), LastName = sample(LETTERS[3:6],size=3, replace=TRUE), StartDate = c("1/31/2000","2/1/2000","3/1/2000"), EndDate = c("1/31/2010"

r mutate_each function is deprecated

点点圈 提交于 2020-01-04 02:03:12
问题 I use the function mutate_each from the tidyverse package and I get a message this function is deprecated. I would like to use the other functions that are not deprecated to change field types. Below is a reproducible example of how I currently employ mutate_each. library(tidyverse) set.seed(123) df <- data.frame(FirstName = sample(LETTERS[1:2],size=3, replace=TRUE), LastName = sample(LETTERS[3:6],size=3, replace=TRUE), StartDate = c("1/31/2000","2/1/2000","3/1/2000"), EndDate = c("1/31/2010"

dplyr mutate using variable columns

家住魔仙堡 提交于 2020-01-03 16:57:17
问题 I am trying to use mutate to create a new column with values based on a specific column. Example final data frame (I am trying to create new_col ): x = tibble(colA = c(11, 12, 13), colB = c(91, 92, 93), col_to_use = c("colA", "colA", "colB"), new_col = c(11, 12, 93)) I would like to do something like: x %>% mutate(new_col = col_to_use) Except instead of column contents, I would like to transform them to a variable. I started with: col_name = "colA" x %>% mutate(new_col = !!as.name(col_name))

dplyr: deselecting columns given by

送分小仙女□ 提交于 2020-01-03 09:10:11
问题 How can I deselect columns given in the ... argument of a self written function. (I also need to select the columns at another point, so just specifying the columns with - in ... does not solve my problem.) Any soltions are apreciated, select -helpers, manipulating quosures or expressions, ... # very simple example data test <- data.frame(a=1:3, b=1:3, c=1:3) # function skeleton testfun <- function(x, ...){ y <- select(x, ...) z <- select(x, -...) # does of course not work like this return

How do you use approx() inside of mutate_at()?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 18:17:41
问题 I'm having issues getting approx() to work inside of a mutate_at(). I did manage to get what I want using a very long mutate() function, but for future reference I was wondering if there was a more graceful and less copy-pasting mutate_at() way to do this. The overarching problem is merging a dataset with data from 1 year intervals to one with 3 year intervals, and interpolating years with no data in the dataset with 3 year intervals. There are missing values in between the years, and one

How do you use approx() inside of mutate_at()?

我与影子孤独终老i 提交于 2020-01-02 18:17:10
问题 I'm having issues getting approx() to work inside of a mutate_at(). I did manage to get what I want using a very long mutate() function, but for future reference I was wondering if there was a more graceful and less copy-pasting mutate_at() way to do this. The overarching problem is merging a dataset with data from 1 year intervals to one with 3 year intervals, and interpolating years with no data in the dataset with 3 year intervals. There are missing values in between the years, and one

Using broom and tidyverse to summarise r squared gams

穿精又带淫゛_ 提交于 2020-01-02 11:16:12
问题 I posted a question here and was able to reproduce Claus' answer to calculate multiple r-squared values for each species in an additive model using tidyverse on iris data. However, an update occurred for packages and now R-sq values are not being calculated. Not sure why... Here are clause response and output library(tidyverse) library(broom) iris %>% nest(-Species) %>% mutate(fit = map(data, ~mgcv::gam(Sepal.Width ~ s(Sepal.Length, bs = "cs"), data = .)), results = map(fit, glance), R.square

What is the best way to calculate and display peaks of a ggplot2::geom_density() object?

落爺英雄遲暮 提交于 2020-01-02 10:09:05
问题 I'm trying to find an easy and intuitive way to calculate and display the peaks of a ggplot2::geom_density() object. This blog explains how to do it in base R, but it is a multistep process. But it seems much more intuitive to use the stat_peaks() function of the ggpmisc package. However, when running the code below, I get the error: stat_peaks requires the following missing aesthetics: y library(tidyverse) library(ggpmisc) ggplot(iris, aes(x = Petal.Length)) + geom_density() + stat_peaks

write_csv read_csv with scientific notation after 1000th row

你离开我真会死。 提交于 2020-01-02 06:11:59
问题 Writing a data frame with a mix of small integer entries (value less than 1000) and "large" ones (value 1000 or more) into csv file with write_csv() mixes scientific and non-scientific entries. If the first 1000 rows are small values but there is a large value thereafter, read_csv() seems to get confused with this mix and outputs NA for scientific notations: test_write_read <- function(small_value, n_fills, position, large_value) { tib <- tibble(a = rep(small_value, n_fills)) tib$a[position]

write_csv read_csv with scientific notation after 1000th row

徘徊边缘 提交于 2020-01-02 06:10:11
问题 Writing a data frame with a mix of small integer entries (value less than 1000) and "large" ones (value 1000 or more) into csv file with write_csv() mixes scientific and non-scientific entries. If the first 1000 rows are small values but there is a large value thereafter, read_csv() seems to get confused with this mix and outputs NA for scientific notations: test_write_read <- function(small_value, n_fills, position, large_value) { tib <- tibble(a = rep(small_value, n_fills)) tib$a[position]