R 在向量末尾添加字符串时遇到问题,该向量为';名单上有什么
想知道如何在食物中添加另一种元素吗?R 在向量末尾添加字符串时遇到问题,该向量为';名单上有什么,r,list,vector,append,R,List,Vector,Append,想知道如何在食物中添加另一种元素吗? 尝试过食物g[[“食物”]使用purr的一个选项可以是: g[["food"]] <- c(g[["food"]], "asparagus") 如果 modify_in(g, "food", ~ c(., "asparagus")) $vegetable [1] "carrot" $food [1] "steak" "eggs" "asparagus" $numbers [1] 4 2 1 7 或者使用modifyList
尝试过食物
g[[“食物”]使用purr
的一个选项可以是:
g[["food"]] <- c(g[["food"]], "asparagus")
如果
modify_in(g, "food", ~ c(., "asparagus"))
$vegetable
[1] "carrot"
$food
[1] "steak" "eggs" "asparagus"
$numbers
[1] 4 2 1 7
或者使用
modifyList
frombase R
library(purrr)
map_if(g, names(g) == 'food', ~ c(.x, 'asparagus'))
#$vegetable
#[1] "carrot"
#$food
#[1] "steak" "eggs" "asparagus"
#$numbers
#[1] 4 2 1 7
基R解
modifyList(g, list(food = c(g[['food']], 'asparagus')))
#$vegetable
#[1] "carrot"
#$food
#[1] "steak" "eggs" "asparagus"
#$numbers
#[1] 4 2 1 7
g[[“食品”]]
modifyList(g, list(food = c(g[['food']], 'asparagus')))
#$vegetable
#[1] "carrot"
#$food
#[1] "steak" "eggs" "asparagus"
#$numbers
#[1] 4 2 1 7
g <- within(g,food <- c(food,"asparagus"))
g <- within(g,food <- append(food,"asparagus"))
> g
$vegetable
[1] "carrot"
$food
[1] "steak" "eggs" "asparagus"
$numbers
[1] 4 2 1 7