with 255 more rows, and 2 more variables: sex <fct>, year <int> # ---3 penguins %>% filter(species == "Adelie" & bill_length_mm > 40) ## # A tibble: 50 × 8 ## species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g ## <fct> <fct> <dbl> <dbl> ...
X[2,2] <- NA X[4,1] <- NA X ### 1.去掉含有NA的行,可以选择只根据某一列来去除 drop_na(X)#去掉X矩阵中所有的NA drop_na(X,X1)#去掉X矩阵中列X1中带有NA的行 drop_na(X,X2)#去掉X矩阵中列X2中带有NA的行 ### 2.替换NA replace_na(X,list(X2=0))#把X2中的NA值替换为0 ##...
针对数据集中的缺失值,可以通过重新编码处理,还可以直接删除缺失值/缺失值行 删除缺失值行:na.omit > df <- matrix(c(1:5,NA,7:10),nrow=5)> df[,1] [,2][1,]1NA[2,]27[3,]38[4,]49[5,]510> df <-na.omit(df)> df[,1] [,2][1,]27[2,]38[3,]49[4,]510attr(,"na.action...
类似于 rbind、cbind 函数,但这两个函数会对行列进 行更加严格的检查,所以使用 bind_rows 纵向合并时,可以根据变量 名合并数据;而使用 bind_cols 横向合并时,需要两个数据框拥有相同 数量的观测值。 > df <- tibble(x = 1:3, y = 3:1) > df1 <- tibble(x = 4, y = 0) > df2 <- tibble(z...
删除缺失值行:na.omit() > df <- matrix(c(1:5,NA,7:10),nrow=5)> df [,1] [,2][1,] 1 NA[2,] 2 7[3,] 3 8[4,] 4 9[5,] 5 10> df <-na.omit(df)> df [,1] [,2][1,] 2 7[2,] 3 8[3,] 4 9[4,] 5 1...
87 x 4#> name hair_color skin_color eye_color#> <chr> <chr> <chr> <chr>#> 1 Luke Skywalker blond fair blue#> 2 C-3PO <NA> gold yellow#> 3 R2-D2 <NA> white, blue red#> 4 Darth Vader none white yellow#> 5 Leia Organa brown light brown#> # … with 82 more rowsstarwa...
# ... with 22 more rows 1.5 汇总: summarise() 对数据框调用其它函数进行汇总操作, 返回一维的结果: summarise(mtcars_df,mdisp=mean(disp,na.rm=TRUE))# A tibble: 1 x 1mdisp<dbl>1230.7219 1.6 分组: group_by() 当对数据集通过group_by()添加了分组信息后,mutate(),arrange() 和 summarise()...
arrange()changes the ordering of the rows. These all combine naturally withgroup_by()which allows you to perform any operation “by group”. You can learn more about them invignette("dplyr"). As well as these single-table verbs, dplyr also provides a variety of two-table verbs, which yo...
(dplyr)duplicates 过滤标准2(推荐):#仅保留在一半以上样本里表达的基因exp5 = exp4[apply(exp4, 1, function(x) sum(x > 0) > 0.5...#2,函数会应用于矩阵的每一行(即,纵向)。...simplify = T)[,1]group= g %>% str_remove("_\\d")table(group)## group## NC OMV2 ## 3 3#...
# ... with 22 more rows 1.5 汇总: summarise() 对数据框调用其它函数进行汇总操作, 返回一维的结果: summarise(mtcars_df,mdisp=mean(disp,na.rm=TRUE))# A tibble: 1 x 1mdisp<dbl>1230.7219 1.6 分组: group_by() 当对数据集通过group_by()添加了分组信息后,mutate(),arrange() 和 summarise()...