2013-10-23 38 views
-1

我有个字符向量:独立数据

A <- c("terrestrial human", 
     "animal 7 planet", 
     "geographic 23 locations", 
     "discovery kids") 

我想此分离成两个向量:一个具有包含数字的所有条目,并且没有任何数字的其它含数据。

v1 <- c("animal 7 planet","geographic 23 locations") 
v2 <- c("terrestrial human","discovery kids") 
+0

您是否尝试过使用'grepl'? – TheComeOnMan

+0

请提供[可重现的示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。 – Thomas

+1

你似乎有一个向量。 “x < - c”(“陆地人类”,“动物7星球”,“地理位置23”,“发现孩子”); split(x,grepl(“[0-9]”,m))' –

回答

1

我把声明Matrix A的自由作为载体称为A代替,因为它似乎是一维 -

A[!grepl(x = A, pattern = '[[:digit:]]')] 
A[grepl(x = A, pattern = '[[:digit:]]')]