Package taxlist version 0.2.4
这是一系列功能,旨在快速编码替换,既作为内部功能,也用于处理存储在向量和数据帧中的信息的工作流中。此类函数在处理存储在 taxlist 对象中的功能特征时特别有用。
replace_x() 用于替换向量中的值。
replace_idx() 通过匹配索引或条件来更改向量中的值。
函数 replace_na() 的工作方式与 replace_idx() 相同,但只会在空元素 (NA) 中插入值。
函数 insert_rows() 将同时添加行和列。当一个新表追加到另一个表但仅共享部分列时,将使用此函数。
replace_x(x, old, new)
replace_idx(x, idx1 = x, idx2 = idx1, new)
replace_na(x, idx1, idx2 = idx1, new)
insert_rows(x, y)
参数【x】:要修改的向量。在 insert_rows() 的情况下,x 是一个数据框。
参数【old】:一个向量,它的值要被replace_x() 替换。
参数【new】:一个向量,用来替换别的值,可以是数值,也可以是索引。
参数【idx1,idx2】:应用于值替换的索引,以分别将 x 与 new 匹配。如果未提供 idx2,则假定它等效于 idx1。
参数【y】:插入 x 的数据框。
具有修改值的向量或数据框。
replace_x(x = letters, old = c("b", "p", "f"), new = c("bee", "pork", "fungus"))
[1] "a" "bee" "c" "d" "e" "fungus" "g" [8] "h" "i" "j" "k" "l" "m" "n" [15] "o" "pork" "q" "r" "s" "t" "u" [22] "v" "w" "x" "y" "z"
replace_idx(x = letters, idx1 = 1:length(letters), idx2 = c(2, 7, 17),
new = c("second", "seventh", "seventeenth"))
[1] "a" "second" "c" "d" [5] "e" "f" "seventh" "h" [9] "i" "j" "k" "l" [13] "m" "n" "o" "p" [17] "seventeenth" "r" "s" "t" [21] "u" "v" "w" "x" [25] "y" "z"
letters[2] <- NA
replace_na(x = letters, idx1 = 1:length(letters), idx2 = c(1:3),
new = c("alpha", "beta", "zeta"))
[1] "a" "beta" "c" "d" "e" "f" "g" "h" "i" [10] "j" "k" "l" "m" "n" "o" "p" "q" "r" [19] "s" "t" "u" "v" "w" "x" "y" "z"
summary(as.factor(Easplist$life_form))
acropleustophyte chamaephyte climbing_plant 8 25 25 facultative_annual obligate_annual phanerophyte 20 114 26 pleustohelophyte reed_plant reptant_plant 8 14 19 tussock_plant NA's 52 3576
Easplist@taxonTraits$lifeform <- replace_x(x = Easplist@taxonTraits$life_form,
old = c("obligate_annual", "facultative_annual"), new = c("annual", "annual"))
summary(as.factor(Easplist$lifeform))
acropleustophyte annual chamaephyte climbing_plant 8 134 25 25 phanerophyte pleustohelophyte reed_plant reptant_plant 26 8 14 19 tussock_plant NA's 52 3576
Easplist@taxonTraits$lifeform <- replace_idx(x = Easplist@taxonTraits$life_form,
idx1 = grepl("annual", Easplist@taxonTraits$life_form), idx2 = TRUE,
new = "annual")
summary(as.factor(Easplist$lifeform))
acropleustophyte annual chamaephyte climbing_plant 8 134 25 25 phanerophyte pleustohelophyte reed_plant reptant_plant 26 8 14 19 tussock_plant NA's 52 3576
data(iris)
iris$Species <- paste(iris$Species)
new_iris <- data.frame(Species = rep("humilis", 2), Height = c(15, 20),
stringsAsFactors = FALSE)
insert_rows(iris, new_iris)