[R] str_count counts the substring

arun smartpink111 at yahoo.com
Mon Sep 30 12:56:33 CEST 2013


Hi,

May be this helps:
str1<- "Brazil is the world's leading orange producer, with an output almost as high as that of the next three countries combined (the United States, India, and China). Orange groves are located mainly in the state of São Paulo, in the southeastern region of Brazil. Oranges, whose flavour may vary from sweet to sour, are commonly peeled and eaten fresh or squeezed for juice ora"

regmatches(str1,gregexpr("\\borange\\b",tolower(str1),perl=TRUE))[[1]]
#[1] "orange" "Orange"


 length(regmatches(str1,gregexpr("\\borange\\b",tolower(str1),perl=TRUE))[[1]])
#[1] 2
A.K.







----- Original Message -----
From: agrima srivastava <agrimasrivastava1 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, September 30, 2013 1:45 AM
Subject: [R] str_count counts the substring

I am trying to count the number of times a word occurs in a string.
and using str_count function from the package stringr. This function counts
the substrings as well.
Is there a way in which I can exclude the substring count and just take the
exact match.
Thanks in advance.



-- 
Thanks and Regards
Agrima Srivastava
-------------------------------------------------------------------------------
Research Scholar
Computer Science & Information Systems Department
BITS Pilani Hyderabad Campus

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
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