col_1
NN
NaN
NI
II
How do I change it to:
col_2
0/0
../0
0/1
1/1
where N=0, Na=.., I=1
, with / in between the two numbers?
I tried using for loops but it was a mess and I dont know how to add the / in the middle... Thank you so much in advance!
You can try to apply following function. It uses regex expressions and substitution.
adjust_text <- function(text){
text <- gsub('Na', '../', text)
text <- gsub('N', '0/', text)
text <- gsub('I', '1/', text)
text <- gsub('(.$)', '', text)
return(text)}
Sample output:
['0/0', '../0', '0/1', '1/1']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With