I have a data frame that contains numbers and numbers separated by a "." and I want to change the entries dependent on the "." string. If the entry does not contain a "." the prefix "-" should be added. That's kind of simple using the subsetting or grep functionality. But I also want to replace the entries which contain a "." with the counter of ".".
my example data:
X1 X2
1 2
3 4
6 8
5 1.2
3.4 7
1.2.5 9
11 3.4.7
and I would like to have it look like this:
X1 X2
-1 -2
-3 -4
-6 -8
-5 1
2 -7
3 -9
-11 4
I have no clue and tried already subsetting, extracting the "." parts to count them. But I can not insert the counter. Thanks for your help.