[英]Changing character to numeric in data.frame (as.numeric) with thousand separator
[英]Return the unique character elements that are mixed with numeric ones in a data.frame
假设我有一个 data.frame,它主要由数值组成,但也混合了一些字符元素。
有没有办法在整个 data.frame 中提取唯一的字符元素?
下面显示了一个玩具示例以及所需的输出?
DF <- data.frame(x = c(1:3, "*", "."), y = c("--", 4:6, "="), z = 1:5, w = rep("a", 5))
desired_output <- c("*", ".", "--", "=")
您可以使用grep
从DF
提取所有只有标点符号的值:
unique(grep('^[[:punct:]]+$', as.character(unlist(DF)), value = TRUE))
#[1] "*" "." "--" "="
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.