使用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 ...
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 2)ends_with()选择以“XX”结尾的所有列 msleep%>% select(ends_with("e")...
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 %...
df%>%select(start_with("n")) 3 filter() filter()是对数据行方向的选择和筛选,选出符合我们条件的某些行: 代码语言:javascript 复制 df%>%filter(type=="english",score>85)df%>%filter(between(score,80,90)) 4 summarize() summarize()主要用于统计,往往与其他函数配合使用,比如计算所有同学考试成绩的...
starts_with('abc'):匹配开头为'abc'的值 ends_with('xyz'):匹配结尾为'xyz'的值 contains('ijk'):匹配包含'ijk'的值 matches('(.)\\1'):通过正则表达式来匹配 num_range('x', 1:3):选取x1~x3变量;类似于基础的R索引搭配paste()函数,用来选取命名规律的变量 ...
Show the Data Reduce the Clutter Integrate Graphics and Text Small Multiples Start with Gray 每条指南详细的介绍,请阅读下面网址。 lenkiefer.com/2021/02/204 R语言编码风格指南 R大神Hadley Wickham所说: 好的编码风格就像使用正确的标点符号。你可以不用它,但它确实让内容更容易阅读。 好的R语言编码,可...
另外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...
purrr is an R package that enhances R’s functional programming toolkit by providing a complete and consistent set of tools for working with functions and vectors. The best place to start with purrr is the family of map() functions that allow you to replace many for loops with code that ...