regexpr(), assumindo que, qdo vc diz "segunda linha", vc realmente queira dizer "segundo caracter da respectiva linha".<div><br></div><div>se vc precisa mesmo que os outros valores sejam 0, algo como o seguinte funciona como ponto de partida:</div>

<div><br></div><div>pmax(regexpr("A30", linha), 0)<br><div><br></div><div>b</div><div><br><div class="gmail_quote">2012/3/21 Sérgio Henrique almeida da silva ju <span dir="ltr"><<a href="mailto:sergio.edfisica@gmail.com">sergio.edfisica@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Olá<br><br>Estou trabalhando com um banco de mortalidade (SIM) no R e gostaria de uma ajuda.<br><br>Quero criar uma variável que me diz a posição de um valor em uma variável<br>

<br>Exemplo:<br><br>Banco Original<br>



        
        
        
        
        
        



<table frame="VOID" rules="NONE" height="136" width="229" border="0" cellspacing="0" cols="2">
        <colgroup><col width="158"><col width="67"></colgroup>
        <tbody>
                <tr>
                        <td align="LEFT" height="17" width="158"><font>linhaa</font></td>
                        <td align="LEFT" width="67"><font>linhab</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font><br></font></td>
                        <td align="LEFT"><font><br></font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*T792</font></td>
                        <td align="LEFT"><font>*X990</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*S069</font></td>
                        <td align="LEFT"><font>*X954</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*R092*T792</font></td>
                        <td align="LEFT"><font>*J189</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*R571</font></td>
                        <td align="LEFT"><font>*T792</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*A301</font></td>
                        <td align="LEFT"><font><br></font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="17"><font>*T792</font></td>
                        <td align="LEFT"><font>*X990*A302</font></td>
                </tr>
        </tbody>
</table>



<br>Criando a variável x1 e x2<br><br>



        
        
        
        
        
        



<table frame="VOID" rules="NONE" border="0" cellspacing="0" cols="4">
        <colgroup><col width="103"><col width="103"><col width="29"><col width="29"></colgroup>
        <tbody>
                <tr>
                        <td align="LEFT" height="20" width="103"><font size="3">linhaa</font></td>
                        <td align="LEFT" width="103"><font size="3">linhab</font></td>
                        <td align="LEFT" width="29"><font size="3">x1</font></td>
                        <td align="LEFT" width="29"><font size="3">x2</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*T792</font></td>
                        <td align="LEFT"><font size="3">*X990</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*S069</font></td>
                        <td align="LEFT"><font size="3">*X954</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*R092*T792</font></td>
                        <td align="LEFT"><font size="3">*J189</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*R571</font></td>
                        <td align="LEFT"><font size="3">*T792</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*A301</font></td>
                        <td align="LEFT"><font size="3"><br></font></td>
                        <td align="RIGHT"><font size="3">2</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                </tr>
                <tr>
                        <td align="LEFT" height="20"><font size="3">*T792</font></td>
                        <td align="LEFT"><font size="3">*X990*A302</font></td>
                        <td align="RIGHT"><font size="3">0</font></td>
                        <td align="RIGHT"><font size="3">7</font></td>
                </tr>
        </tbody>
</table>



<br>Ou seja, o valor A30, começa na segunda linha da variável linhaa e na 7 linha da variável linhab<br><br>Como rodar isso no R, no SPSS o comando é:<br><br>compute x1 = index(linhaa, "A30").<br>compute x2 = index(linhab, "A30").<br clear="all">


...<br>execute.<br><br><br>Obrigado<span class="HOEnZb"><font color="#888888"><br><br>-- <br>Sérgio Henrique Almeida da Silva Junior<br>Doutorando em Epidemiologia em Saúde Pública<br>Escola Nacional de Saúde Pública Sérgio Arouca - ENSP/FIOCRUZ<br>

<a href="http://lattes.cnpq.br/1611345552843383" target="_blank">http://lattes.cnpq.br/1611345552843383</a> <br>
Tel: (21) 94429486/78101651 id: 123*20942<br><br><br>
</font></span><br>_______________________________________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
<a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>
Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e forneça código mínimo reproduzível.<br></blockquote></div><br></div></div>