我想知道如何从下面的字符串
Vector
中删除“list()”以获得我的desired_output
?
Vector = c("Nc", "list(\"Year\")", "list(\"# of Treatments\")")
gsub("list","", Vector) # doesn't fully work
desired_output = c("Nc", "Year", "# of Treatments")
根据您的样本数据,您可以使用:
gsub("\"|\\\\|list\\(|\\)", "", Vector)
[1] "Nc" "Year" "# of Treatments"
它只是查找引号 (
\"
) 或反斜杠 (\\\\
) 或 list(
或右括号 (\\)
)