R : Column operation on a data frame -
I have a column in my data frame df
which ratio
It is separated from two positive integers x
and y
[that is, format is x / Y
]. I would like to replace each line in this column with the integer ((x / y) * 10)
(round in the nearest integer)
example, for example if one Element 14/20
in ratio
I have to change it to 7
.
[A level 0/0
in the ratios
column in which I want it to be 5
]
Here's an approach:
# Example data frame & gt; Dat & lt; - data.frame (ratio = c ("0/0", "14/20")) conversion (dat, ratio 2 = sapply (strsplit (as.character (ratio), "/"), function (x) if (X [2] == "0") 5 more goals (decrease ("/", as.inger (x)) * 10))) # ratio ratio 2 # 1/0/05 # 2 14/20 7
Comments
Post a Comment