r - 从数据框中的字符向量中提取第二个观察值
问题描述
c()
从数据框中的向量中提取第二个观察值。
我有一些看起来像这样的数据:
splitNames
1 , grupo, modelo, s.a.b., de, c.v.
2 , gymboree
3 , cerner
4 , stellus, capital, investment
5 , cambium, learning, group
6 , cornell, companies
7 , the, boeing
8 , wd-40, co
9 , glencore
10 , the, valspar
我想从数据中提取grupo
, gymboree
, cerner
, stellus
, cambium
, Cornell
, the
, wd-40
,Glencore
和the
。目前我可以做到,但它只grupo
从数据中提取。y %>% mutate(splitNames[[1]][[2]])
数据:
structure(list(splitNames = list(c("", "grupo", "modelo", "s.a.b.",
"de", "c.v."), c("", "gymboree"), c("", "cerner"), c("", "stellus",
"capital", "investment"), c("", "cambium", "learning", "group"
), c("", "cornell", "companies"), c("", "the", "boeing"), c("",
"wd-40", "co"), c("", "glencore"), c("", "the", "valspar"))), class = "data.frame", row.names = c(NA,
-10L))
解决方案
我们可以[
在没有匿名函数的情况下使用
sapply(data$splitNames, `[`, 2)
#[1] "grupo" "gymboree" "cerner" "stellus" "cambium" "cornell" "the" "wd-40" "glencore" "the"
推荐阅读
- openedge - 正在更新数据字段 4gl
- python - Python - Group by dates
- linux - On a PREEMPT_RT linux kernel, how can I modify threads (that were previously ran as interrupts) priority in the pre-compilation stage?
- php - How to explain this php floating point and integer comparison and printing problem?
- file - Is there a specific mime type for storing AES encrypted files?
- flutter - How to create an inner shadow for custom shape in Flutter?
- html - Adaptative height of cell of display:grid
- orientdb - Graph DB and Relations from Edges
- javascript - 如果元素包含值,则排序数组
- c# - SQL to LINQ 涉及多个 GroupJoin