如何简化R中一行列表的代码?

How to simplify the codes of a list in one line in R?

我有一个包含基因符号加入的微阵列平台文本文件列表。我 trim 具有以下代码的基因符号。

p[[1]]<- data.frame(sapply(p[[1]], function(x) sub("/.*", "", x)))
p[[1]]<- data.frame(sapply(p[[1]], function(x) sub("-.*", "", x)))
p[[1]]<- data.frame(sapply(p[[1]], function(x) sub("\..*", "", x)))
p[[1]]<- data.frame(sapply(p[[1]], function(x) sub("\s", "", x)))
p[[2]]<- data.frame(sapply(p[[2]], function(x) sub("/.*", "", x)))
p[[2]]<- data.frame(sapply(p[[2]], function(x) sub("-.*", "", x)))
p[[2]]<- data.frame(sapply(p[[2]], function(x) sub("\..*", "", x)))
p[[2]]<- data.frame(sapply(p[[2]], function(x) sub("\s", "", x)))

如何将这些代码简化为两行? 非常感谢任何想法。

使用等同于逻辑 OR:

的正则表达式的管道运算符
p[[1]] <- data.frame(sapply(p[[1]], function(x) sub("/.*|-.*|\..*|\s", "", x)))

p[[2]] <- data.frame(sapply(p[[2]], function(x) sub("/.*|-.*|\..*|\s", "", x)))