I have dataframe, contains 4 columns. The sample dataframe look likes this
id name description parent_id
001 A A may increase the activities of B 009
002 E A may be increased the activities of C 013
007 F A may decrease the activities of D 055
010 G A may be decreased the activities of G 067
011 K A may increase the activities of X 100
Now, I want to split the dataframe into 2 dataframe based on the word increase/increased and decrease/decreased from the description column.
I am extremely sorry that I do not have any reproducible code. When I am searching Google, StackOverflow I found that, splitting dataframe only for column or rows words.
suppressPackageStartupMessages({
library(dplyr)
library(stringr)
})
# to import data to workspace only
df_ <- readr::read_csv("/home/roc/Desktop/grist.csv")
#>
#> ── Column specification ────────────────────────────────────────────────────────
#> cols(
#> id = col_character(),
#> name = col_character(),
#> description = col_character(),
#> parent_id = col_character()
#> )
df_
#> # A tibble: 5 x 4
#> id name description parent_id
#> <chr> <chr> <chr> <chr>
#> 1 001 A A may increase the activities of B 009
#> 2 002 E A may be increased by the activities of C 013
#> 3 007 F A may decrease the activities of D 055
#> 4 010 G A may be decreased by the activities of G 067
#> 5 011 K A may increase the activities of X 100
df_ %>% filter(str_detect(description,"inc")) -> df1
df1
#> # A tibble: 3 x 4
#> id name description parent_id
#> <chr> <chr> <chr> <chr>
#> 1 001 A A may increase the activities of B 009
#> 2 002 E A may be increased by the activities of C 013
#> 3 011 K A may increase the activities of X 100
df_ %>% filter(str_detect(description,"dec")) -> df2
df2
#> # A tibble: 2 x 4
#> id name description parent_id
#> <chr> <chr> <chr> <chr>
#> 1 007 F A may decrease the activities of D 055
#> 2 010 G A may be decreased by the activities of G 067
Created on 2020-10-27 by the reprex package (v0.3.0.9001)