tidyverse

Encoding issue in tidyverse startup message in RStudio: distorted UTF-8 output (<U+2713>)

ⅰ亾dé卋堺 提交于 2020-01-11 12:23:14
问题 Some time ago everything was ok. But after recent updates (I cannot track down which ones), in RStudio the "Attaching packages" section of the tidyverse startup message has encoding issues while the "Conflicts" part is correct. In R Gui this issue is not present (and there are no different colors). How can I get a non-distorted tidyverse startup message in RStudio? (With v and not <U+2713> ). Is it a bug in some package or RStudio? Are there some settings incorrect on my side? Rstudio version

Looping across multiple variables and parameters using map() and mutate()

一个人想着一个人 提交于 2020-01-11 11:54:17
问题 I'm having trouble figuring out how to effective map across multiple parameters and variables within a tbl to generate new variables. In the "real" version, I basically have one mathematical function generating a central estimate, and I need to run a whole series of sensitivity tests varying different parameters. I'm trying to figure out how to do this within the tidyverse. It looks like map() and mutate() are the answers to this, but I'm having trouble. # building the practice dataset pracdf

take unique count and sum each unique values in R

大兔子大兔子 提交于 2020-01-07 08:32:24
问题 Case1: Input ST_DATE ND_DATE LO_NO ACTV_CODE ACTV_AMT AB_NO FEATURE_CODE L_NU 7/27/16 7/27/16 265 O 15 1 INTEREST 855 7/27/16 7/27/16 265 O 14 1 INTEREST 855 Expected output ST_DATE ND_DATE LO_NO ACTV_CODE ACTV_AMT AB_NO FEATURE_INTEREST L_NU 7/27/16 7/27/16 265 O 29 1 2 855 Case2: Input (my code is working for case2 but throwing error for case1) ST_DATE ND_DATE LO_NO ACTV_CODE ACTV_AMT AB_NO FEATURE_CODE L_NU 7/27/16 7/27/16 265 O 15 1 INTEREST 855 7/27/16 7/27/16 265 O 14 1 INSTALLMENT 855

non zero exit when installing package, only tidyverse

孤街醉人 提交于 2020-01-06 14:53:08
问题 I've set up hosted RStudio on Ubunto and have loaded several packages already with no issues, including caret and lubridate. However, when I tried to install tidyverse I get: > install.packages("tidyverse", dependencies = T) Installing package into ‘/home/rstudio/R/x86_64-pc-linux-gnu-library/3.4’ (as ‘lib’ is unspecified) trying URL 'https://cloud.r-project.org/src/contrib/tidyverse_1.2.1.tar.gz' Content type 'application/x-gzip' length 61647 bytes (60 KB) ===================================

R - Wrong error message - Error: Duplicate identifiers for rows [duplicate]

江枫思渺然 提交于 2020-01-06 06:16:12
问题 This question already has an answer here : How to spread columns with duplicate identifiers? (1 answer) Closed 2 years ago . I have a problem with a dataframe that I need to reshape. I have this command: library(tidyverse) df1 = df1 %>% gather(Day, value, Day01:Day31) %>% spread(Station, value) And I get this error: Error: Duplicate identifiers for rows (130933, 131029), (389113, 389209), (647293, 647389), (905473, 905569), (1163653, 1163749), (1421833, 1421929), (1680013, 1680109), (1938193,

How to name the list of the group_split output in dplyr

橙三吉。 提交于 2020-01-06 04:49:05
问题 I have the following process which uses group_split of dplyr: library(tidyverse) set.seed(1) iris %>% sample_n(size = 5) %>% group_by(Species) %>% group_split() The result is: [[1]] # A tibble: 2 x 5 Sepal.Length Sepal.Width Petal.Length Petal.Width Species <dbl> <dbl> <dbl> <dbl> <fct> 1 5 3.5 1.6 0.6 setosa 2 5.1 3.8 1.5 0.3 setosa [[2]] # A tibble: 2 x 5 Sepal.Length Sepal.Width Petal.Length Petal.Width Species <dbl> <dbl> <dbl> <dbl> <fct> 1 5.9 3 4.2 1.5 versicolor 2 6.2 2.2 4.5 1.5

How to take subsets of lists in a tibble

北战南征 提交于 2020-01-05 04:40:13
问题 I have annual financial data for several stocks. I needed to blow it out to become monthly data and, thanks to an answer to this question I'd asked earlier, I have a solution which involves mutating the date column into lists of dates : library(tidyverse) library(lubridate) factors.subset.raw = structure(list( sec_id = c(1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1572L, 1676L, 1676L, 1676L,

How to renumber result of intersection/group_indices in R?

十年热恋 提交于 2020-01-04 07:36:10
问题 I am struggling with renumbering result from intersection/ group_indices in R for a few days. Sample data frame is shown below: t <- data.frame(mid=c(102,102,102,102,102,102,102,103,103,103,103,103,103,103), aid=c(10201,10202,10203,10204,10205,10206,10207, 10301,10302,10303,10304,10305,10306,10307), dummy=c(0,1,0,1,0,1,0,0,1,0,1,0,1,0), location=c(0,2,0,4,0,1,0,0,2,0,2,0,3,0) ) I need to update numbers stored in "location" fiels to sequential number by a group of "mid" without changing its

Find the max/min value in a pair of columns

假装没事ソ 提交于 2020-01-04 02:56:11
问题 My data looks like this: df <- tribble( ~A, ~B, 0.2, 0.1, 0.2, 0.3, 0.5, 0.1, 0.7, 0.9, 0.8, 0.9, 0.4, 0.2) How might I select the max/min value between A and B ? Desired Output: A B C 1 0.2 0.1 0.2 2 0.2 0.3 0.3 3 0.5 0.1 0.5 4 0.7 0.9 0.9 5 0.8 0.9 0.9 6 0.4 0.2 0.4 回答1: You could try pmax mutate(df, C=pmax(A,B)) # A B C #1 0.2 0.1 0.2 #2 0.2 0.3 0.3 #3 0.5 0.1 0.5 #4 0.7 0.9 0.9 #5 0.8 0.9 0.9 #6 0.4 0.2 0.4 max gets you the maximum single value of the two columns instead of the "row"

Split Data Every N Columns and rbind Using R

和自甴很熟 提交于 2020-01-04 02:08:46
问题 I have a data frame. In my data set. a, a1 and a2 are the exact same variable. However when you have the same names in r it automatically adds a 1 at the end of the name. df = data.frame(a = rnorm(4), b = rnorm(4), c = rnorm(4), a1 = rnorm(4), b1 = rnorm(4), c1 = rnorm(4), a2 = rnorm(4), b2 = rnorm(4), c2 = rnorm(4), date = seq(as.Date("2019-05-05"),as.Date("2019-05-08"), 1)) print(df) a b c a1 b1 a2 b2 c2 date 1 -1.0938097 1.3948486 1.2805904 1.6187439 1.0200681 -1.4335761 -0.4583526 0