r code for logical indexing from string