Stringr 在位置上选择数据。

Stringr selection of data on location.

正在调用 strsplit:

example <- (strsplit(data$col, ","))

[[1]]
[1] "1", "2", "3", "4", "5"

[[2]]
[1] "4", "5", "6", "7", "8", "9"

我以为我可以在每个中提取倒数第​​二个值;即 4 和 8 通过

 example <- sapply(example, "[", 1)

不是这样的吗?我得到了不寻常的答案

两种选择:

sapply(example, function(x) tail(x, 2)[1]) # option 1
sapply(example, function(x) x[length(x)-1]) # option 2