I have a datatable which looks like the following
> head(mydt)
name b c
1: ao 2 1 GiB
2: bo 2 1.4 Gib
Now, I try to do some cleansing - i try to remove the unit from the values in column c without any loops,.. I did the following:
mydt[,4 :=substr(c,0,gregexpr(pattern=' ',c)[[1]][1]-1)]
What I get is something like this:
> head(mydt)
name b c
1: ao 2 1 G
2: bo 2 1.4
What I expect is the following
> head(mydt)
name b c
1: ao 2 1
2: bo 2 1.4
However, it doesn't work --> it seems to use the same endpoint for all values. What I am doing wrong? How can I access the "current" value?
:=, it seems like you need to study?:=and an introductory data.table text.