2013-10-23 39 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:]]')]