tidyverse

    -2热度

    1回答

    我想要使用dplyr获取由另一列分组的一列中唯一值的数量。优先功能友好,这是我可以把它放在一个功能,它会很容易工作。 因此,例如对于下面的数据帧。 test = data.frame(one=rep(letters[1:5],each=2), two=c(rep("c", 3), rep("d", 2), rep("e", 4), "f")) one two 1 a c 2 a c

    1热度

    1回答

    我不是在purrr::modify_if语法中寻求基本的东西。 假设我想要做一些愚蠢的事情 - 将任何名称为2个字符长的变量剪下来。 ,这里是我的尝试: library(tidyverse) library(stringr) library(magrittr) mtcars %>% modify_if(~. %>% names %>% str_leng

    2热度

    3回答

    我有这样的事情: ids <- c("A","B","C") ls <- list() ls[[1]] <- c("aa","aaa") ls[[2]] <- c("bb","bbb") ls[[3]] <- c("cc","ccc") ,我想获得的东西喜欢下: data.frame(ids = c("A","A","B","B","C","C"), ls = c("aa","aaa"

    0热度

    3回答

    我想用收集函数整理我的数据,但是如何一次指定多个列? 说这是我的数据: Country Country.Code Year X0tot4 X5tot9 X10tot14 X15tot19 X20tot24 1 Viet Nam 704 1955 4606 2924 2389 2340 2502 2 Viet Nam 704 1960 5842 4410 2860 2356

    3热度

    2回答

    有时,当从列表生成数据帧时,变量名为“。”。默认。我怎样才能在dplyr函数中引用这个变量,如果只是把变量名改为更合适的话。 # Code that produces my data frame with "." as column name library(tidyverse) d <- data.frame(`.` = 1, row.names = "a") # Now my cod

    2热度

    1回答

    可以as_factor从forcats返回一个有序的因子?这似乎是一个缺失的功能,如果没有,虽然我没有看到它作为GitHub page上的问题报告。 我曾尝试: y <- forcats::as_factor(c("a", "z", "g"), ordered = TRUE) is.ordered(y) # FALSE 如果我不能那么有没有在做任何潜在的危险: y <- ordered(f

    0热度

    2回答

    通常,当我想重新排列例如条形图时,我使用ggplot轴上的reorder()函数。现在这是一个选项,但它有时会让我迷惑coord_flip(),我不太喜欢这种做事的方式。我宁愿操纵数据本身。 我的数据帧: library(tidyverse) warCasualties <- tibble(Who = c("N. Vietnam + communist allies", "So

    1热度

    1回答

    我已经确定,如果不是自己创建的,困难的错误在一些不错的代码解决从这里StackOverflow上慷慨申请人收到几个星期前,我今天可以使用一些新的援助。 样本数据(下面称为对象eh): ID 2013-03-20 2013-04-09 2013-04-11 2013-04-17 2013-04-25 2013-05-15 2013-05-24 2013-05-25 2013-05-26

    0热度

    3回答

    我想创建一个新列,其中每个值都是我的数据中该行其他值的随机子集。 # Example data: df <- data.frame(matrix(nrow = 57, ncol = 6)) %>% mutate( X1 = round(rnorm(n = 57, mean = 0, sd = 1), 1), X2 = round(rnorm(n = 57, mean

    1热度

    2回答

    的列表替换列值我有dataframes的下面的示例清单: cat <- rnorm(5) dog <- rnorm(5) mouse <- rnorm(5) df1 <- cbind(cat,dog,mouse) df2 <- cbind(cat,dog,mouse) df3 <- cbind(cat,dog,mouse) list.1 <- list(df1 = df1,df2