使用start_col:end_col语法选择若干的连续列。 代码语言:javascript 复制 msleep %>% select(name:vore, sleep_total:awake) %>% head(2) 代码语言:javascript 复制 # A tibble: 6 x 7 name genus vore sleep_total sleep_rem sleep_cycle awake <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl> 1 ...
1)starts_with()选择以“XX”开头的所有列 msleep %>%select(name, starts_with("sleep")) %>% head(2)# A tibble: 2 x 4name sleep_total sleep_rem sleep_cycle<chr> <dbl> <dbl> <dbl>1 Cheetah 12.1 NA NA2 Owl monkey 17 1.8 NA2)ends_with()选择以“XX”结尾的所有列msleep %>%select(...
with 140 more rows iris %>% mutate(new_col = 1:n()) #以长度等于行数的向量赋值 ## # A tibble: 150 x 6 ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species new_col ## <dbl> <dbl> <dbl> <dbl> <fct> <int> ## 1 5.1 3.5 1.4 0.2 setosa 1 ## 2 4.9 3 1.4 0.2 ...
如果列名结构相似,可使用starts_with(),ends_with(),contains()完成部分匹配。 1)starts_with()选择以“XX”开头的所有列 msleep%>% select(name,starts_with("sleep"))%>%head(2) # A tibble: 2 x 4 namesleep_totalsleep_remsleep_cycle <chr><dbl><dbl><dbl> 1Cheetah12.1NANA 2Owlmonkey171.8NA ...
1)starts_with()选择以“XX”开头的所有列 msleep %>% select(name, starts_with("sleep")) %>% head(2)# A tibble: 2 x 4 name sleep_total sleep_rem sleep_cycle <chr> <dbl> <dbl> <dbl>1 Cheetah 12.1 NA NA2 Owl monkey 17 1.8 NA 2)ends_with()选择以“XX”结尾的所有列 msleep %...
另外dplyr包中提供了一些实用的函数可以运用在select()中 start_with("abc") : match names that begin with “abc” ends_with("xyz"): matches names that end with “xyz” contains("ijk"): matches names that contain “ijk” num_range("x", 1:3): matches x1, x2 and x3...
6. Select columns with starts_with and ends_with You can select the columns based on start_with and end_with option, here is the example flights %>% select(starts_with("dep_")) flights %>% select(ends_with("hour")) flights %>% select(contains("hour")) This is one of the useful...
plots, insisting on usingggplot2. I also preferggplot2to base-R graphics (though again it should not be considered part of the Tidyverse), but here we have a much more important goal--to give students an actual useful application of R right from the start. Tidy greatly impedes that goal...
# if the first selector is exclusive (negative), start with all columns first <- quo_get_expr(quos[[1]]) initial_case <- if (is_negated(first)) list(seq_along(.vars)) else integer(0) ind_list <- c(initial_case, ind_list) names(ind_list) <- c(names2(initial_case), names...
Microsoft Fabric distributes the latest stable version of tidyverse with every runtime release. Import and start using your familiar R packages.PrerequisitesGet a Microsoft Fabric subscription. Or, sign up for a free Microsoft Fabric trial. Sign in to Microsoft Fabric. Use the experience switcher ...