2015-11-16 29 views
0

我有點卡在這個問題上。我想在第一個數字前刪除這些點,但是我想保留兩個數字之間的任意點。操縱R中的字符串替換小數

。 。 。 。 。 。 。 。 。 。 。 。 。 。 122(100.0)。 。 。 。 。 。 。 。 。 。 。 。 。 。 7(5.7)

例如上述應該輸出到

122(100.0)。 。 。 。 。 。 。 。 。 。 。 。 。 。 7(5.7)

我不知道我應該使用上面做

感謝哪些功能或包!

+1

請提供一個可重現的例子。使用'dput()' – etienne

回答

1

這應該爲你在問什麼工作。

sub('^[\\h.]+', '', x, perl=TRUE) 
1

也許是這樣的:

#copy pasted from your example 
text <- ". . . . . . . . . . . . . . 122 (100.0) . . . . . . . . . . . . . . 7 (5. 7)" 

#find the location of the first number using gregexpr 
loc <- gregexpr('[0-9]', text)[[1]][1] 

#substring the text from loc and until the end 
substr(text, loc, nchar(text)) # or substring(text, loc) 

輸出:

[1] "122 (100.0) . . . . . . . . . . . . . . 7 (5. 7)"