I have a problem where I would appreciate any ideas on how to do it with R. The problem is this: I have a latex-table stored. The numbers in the table are all equipped with three digits after the decimal point. I want to cut these digits off, leaving the others in the table. (Think of the numbers representing estimation results, but with dimension "dollar". Then, a value of 145.553 does not make much sense, and 145 is enough). The person who created these tables did not think too much about this, so here I go trying to avoid going through the table by hand. :)
So far, I only found different solutions for how to extract numbers from strings, not how to change them so that the string itself is unaltered otherwise.
Example:
strings <- c(
"a.name & $-436.735 $ & $-710.832$ \\\\",
"std(a.name) & $(1403.604)$ & $(1274.283)$ \\\\",
)
The solution should return
strings <- c(
"a.name & $-436 $ & $-710$ \\\\",
"std(a.name) & $(1403)$ & $(1274)$ \\\\",
)
and, of course, if it was possible to do the rounding correctly, then it would be even better. But this is not of upmost importance.
I tried using gsub
with \\....
to identify the strings that contain a period followed by three other numbers, but this also gives me the variable names, a.name
in my example.
Does anyone have an idea how I could accomplish what I would like to do?
Thanks in advance!