Question: I have a data grouped data, 

```
df <- data.frame(group_id= c(1, 1, 1, 1, 2, 1, 2, 3, 4),
                words = c("beach", "sand", "trip", "warm","travel", "water","beach","sand", "trees"),
                 ID = c("vacation", "vacation", "vacation", "vacation", "meeting","vacation","meeting","onduty", "hiking"))

```

The `group_id` is groups of `ID` column. Now I want to check certain patterns ("beach" or "warm" or "sand") for each group, and print the matching pattern in separate column and matches 0 (no match) or 1 (yes macth) in separate column.

Expected :

```
  id  words       ID           pattern Match
1  1  beach vacation Beach, sand, warm 1
2  1   sand vacation Beach, sand, warm 1
3  1   trip vacation Beach, sand, warm 1
4  1   warm vacation Beach, sand, warm 1
5  2 travel  meeting Beach             1
6  1  water vacation Beach, sand, warm 1
7  2  beach  meeting Beach             1
8  3   sand   onduty sand              1
9  4  trees  hiking  0                 0

```

Answer: 
This ignores one [line break, see `\R`](https://docs.oracle.com/javase/9/docs/api/java/util/regex/Pattern.html).

Exactly the same could have been done with `\R` - sigh.

```
scanner.skip("\\R?");

```
It is associated to scanner class:

Lets suppose u have input from system console

```
4
This is next line

```

---

```
int a  =scanner.nextInt();
String s = scanner.nextLine();

```

value of a will be read as 4
and value of s will be empty string because nextLine just reads what is next in same line, and after that it shifts to nextLine

---

to read it perfectly, u should add one more time nextLine() like below

```
int a  =scanner.nextInt();
scanner.nextLine();
String s = scanner.nextLine();

```

---

to insure that it reaches to nextline and skips everything if there is any anomaly in the input

```
scan.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 

```

upper line does job perfectly in every OS and environment.