Bioinf_15 - 1 year ago 70

R Question

I'm working with a data matrix I received from a colleague who no longer works in our research group. The numbers are gene expression values. When I read the data.frame using R, numbers look like this: 715.583.892.852.256, 85.363.547.324.901. I don't know why they look like that. Expected numbers are: 715.5, 85.3. Can anyone explain to me why they appear like that? How can I trim the original numbers in order to obtain the desired ones?

Thanks in advance

Answer Source

Here is a brute force way:

```
x <- c("715.583.892.852.256", "85.363.547.324.901")
as.numeric(
sapply(
strsplit(x, "\\."),
function(x)paste(x[1], paste(x[-1], collapse = ""), sep = ".")
)
)
```

This gives:

```
[1] 715.58389 85.36355
```