How to convert this Python code to R?
<p>,I need help with translating a python code into an R code.</p>

<p>I have a data frame df, that contains the column IndicatorOfDefault and I would like too generate a column named indvalues.</p>

<p>Example:</p>

<pre><code>row number   IndicatorOfDefault   indvalues

823602                        P           0 

823603                        P           0

823604                  N1,N13,           8

823605                      N1,           1

823606                        P           0

823607         N1,N2,N3,N9,N10,          13

823608                        P           0
</code></pre>

<p>The code that I want to convert is the following:</p>

<pre><code>df['indicators'] = df['IndicatorOfDefault'].str.split(',')

Nvalues = {'' : -1, 'P' : 0, 'N1' : 1, 'N2' : 2, 'N11' : 3, 'N12' : 4, 'N3' : 5, 'N4' : 6, 
           'N6' : 7, 'N10' : 8, 'N13' : 9, 'N5' : 10, 'N7' : 11, 'N8': 12, 'N9' : 13}

df['indvalues'] = df['indicators'].apply(lambda x: max([Nvalues.get(y,y) for y in x ]))
</code></pre>

<p>I would like to execute the same code in R, but I don't know how to write it in R. </p>

<p>Can anyone help me please?</p>

<p>Thanks in advance</p>

<p>Why is this question off topic? I don't understand what's wrong... I am new to this site, so I would appreciate if someone could explain why this specific problem doesn't belong here? I've read what's written in the help center, but i still don't know what's wrong.</p>

<p>I've managed to solve my problem in a different way. I get the result that I want - the most important indicator (it didn't needed to be a number necessary).</p>

<pre><code>    df$ind &lt;- "P"
for(i in c(1, 2, 11, 12, 3, 4, 6, 10, 13, 5, 7, 8, 9)){
       df &lt;- transform(df, ind = ifelse(grepl(as.character(paste0("N",i,",")),IndicatorOfDefault),as.character(paste0("N",i)),ind))
    }
</code></pre>

<p>Example:</p>

<pre><code>row number   IndicatorOfDefault         ind

823602                        P           P 

823603                        P           P

823604                  N1,N13,         N13

823605                      N1,          N1

823606                        P           P

823607         N1,N2,N3,N9,N10,          N9

823608                        P           P
</code></pre>