2015-11-16 28 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)"