用字母和 numbers/Removing 某些值的前导零划分 R 中的列

Dividing column in R with both letter and numbers/Removing leading zeros of certain values

我有两个问题。我正在尝试使用 R.

删除任何大于 100 的数字的前导零
Obs Phecode
1   008 
2   009
3   1000
4   0100

我希望它看起来像这样

Obs Phecode
1   008 
2   009
3   1000
4   100

另外,有没有一种方法可以将一列除以某个数字,即使有些行中有字母?如果值小于 100,我也希望有前导零,但前提是开头没有字母。

原版Table

Obs ICD
1   99561 
2   980
3   E440
4   V4489

想要Table

Obs ICD
1   995.61 
2   009.8
3   E4.40
4   V44.89

提前致谢!

如果数字大于等于 100,将其更改为数字(as.numeric(..) 删除前导 0)否则保持原值。

df <- transform(df, Phecode = ifelse(as.numeric(Phecode) >= 100, 
                                as.numeric(Phecode), Phecode))

df
#  Obs Phecode
#1   1     008
#2   2     009
#3   3    1000
#4   4     100