[R] substring simultaneous conditions

ruipbarradas at sapo.pt ruipbarradas at sapo.pt
Mon Sep 5 14:41:38 CEST 2016


Hello,

Try placing the & immediately after the substr() conditions, like this:


base <- baseR[substr(baseR[['ID']],3,4)!='03' &
                         substr(baseR[['ID']],11,12)!='01' &
                         substr(baseR[['ID']],11,12)!='11',]


Maybe I'm wrong but R might have decided that the instructions were  
complete before the next lines were reached.
And your attachment didn't make through. Use dput to post a data example.

dput(head(baseR, 30))  #paste the output of this in a mail


Hope this helps,

Rui Barradas




Citando Rosa Oliveira <rosita21 at gmail.com>:

> Dear all,
>
> I have searched all over and didn´t found an answer :( Sorry, I'm new.
>
> I need urgently to "not analyse"the weight the ID's that have 07 in the
> position 3 and 4 respectively, 01 or 11 in positions 11 and 12 of ID
> variable. .
>
> I used the following code:
>
> base<--baseR[substr(baseR$'ID',3,4)!='03'
>                       &substr(baseR$'ID',11,12)!='01'
>                        &substr(baseR$'ID',11,12)!='11',]
>
> But, instead of removing just the id's that respect the 3 conditions
> simultaneously, base don't have all the id's that have 03 in the 3 and 4
> positions os id variable, neither 01  in positions 11 and 12 of ID,  
> neither 11
> in positions 11 and 12 of ID variable.variable.
>
> So, it seems, that the code exclude all the conditions, as it was a OR (|)
> condition in spite of AND (&) condition.
>
> Can anyone help me please?
>
> I attach the data.
>
> Best,
> Rosa Oliveira
>
> __________________________________
>
> Antes de imprimir este e-mail pense bem se tem mesmo que o fazer.
> Há cada vez menos árvores.
> Não imprima, pense na sua responsabilidade e compromisso com o MEIO
> AMBIENTE!
> <http://pt.dreamstime.com/cora-ccedil-atildeo-criado-das-folhas-de-aacutervores-diferentes-thumb12275776.jpg>
> <http://pt.dreamstime.com/cora-ccedil-atildeo-criado-das-folhas-de-aacutervores-diferentes-thumb12275776.jpg>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list