split_word: Split Words

Description Usage Arguments Value Examples

View source: R/split_word.R

Description

Split words.

Usage

1
2
3
4
5
6
7
split_word(x, ...)

## Default S3 method:
split_word(x, lower = TRUE, ...)

## S3 method for class 'data.frame'
split_word(x, text.var = TRUE, lower = TRUE, ...)

Arguments

x

A data.frame or character vector with words.

lower

logical. If TRUE the words are converted to lower case.

text.var

The name of the text variable. If TRUE split_word tries to detect the text column with words.

...

Ignored.

Value

Returns a list of vectors of words or an expanded data.table with words split apart.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(x <- c(
    "Mr. Brown comes! He says hello. i give him coffee.",
    "I'll go at 5 p. m. eastern time.  Or somewhere in between!",
    "go there"
))
split_word(x)
split_word(x, lower=FALSE)

data(DATA)
split_word(DATA)
split_word(DATA, lower=FALSE)

## Larger data set
split_word(hamlet)

Example output

[1] "Mr. Brown comes! He says hello. i give him coffee."        
[2] "I'll go at 5 p. m. eastern time.  Or somewhere in between!"
[3] "go there"                                                  
[[1]]
 [1] "mr"     "brown"  "comes"  "he"     "says"   "hello"  "i"      "give"  
 [9] "him"    "coffee"

[[2]]
 [1] "i'll"      "go"        "at"        "5"         "p"         "m"        
 [7] "eastern"   "time"      "or"        "somewhere" "in"        "between"  

[[3]]
[1] "go"    "there"

[[1]]
 [1] "Mr"     "Brown"  "comes"  "He"     "says"   "hello"  "i"      "give"  
 [9] "him"    "coffee"

[[2]]
 [1] "I'll"      "go"        "at"        "5"         "p"         "m"        
 [7] "eastern"   "time"      "Or"        "somewhere" "in"        "between"  

[[3]]
[1] "go"    "there"

        person sex adult    state code element_id word_id
 1:        sam   m     0 computer   K1          1       1
 2:        sam   m     0       is   K1          1       2
 3:        sam   m     0      fun   K1          1       3
 4:        sam   m     0      not   K1          1       4
 5:        sam   m     0      too   K1          1       5
 6:        sam   m     0      fun   K1          1       6
 7:       greg   m     0       no   K2          2       1
 8:       greg   m     0     it's   K2          2       2
 9:       greg   m     0      not   K2          2       3
10:       greg   m     0     it's   K2          2       4
11:       greg   m     0     dumb   K2          2       5
12:    teacher   m     1     what   K3          3       1
13:    teacher   m     1   should   K3          3       2
14:    teacher   m     1       we   K3          3       3
15:    teacher   m     1       do   K3          3       4
16:        sam   m     0      you   K4          4       1
17:        sam   m     0     liar   K4          4       2
18:        sam   m     0       it   K4          4       3
19:        sam   m     0   stinks   K4          4       4
20:       greg   m     0        i   K5          5       1
21:       greg   m     0       am   K5          5       2
22:       greg   m     0  telling   K5          5       3
23:       greg   m     0      the   K5          5       4
24:       greg   m     0    truth   K5          5       5
25:      sally   f     0      how   K6          6       1
26:      sally   f     0      can   K6          6       2
27:      sally   f     0       we   K6          6       3
28:      sally   f     0       be   K6          6       4
29:      sally   f     0  certain   K6          6       5
30:       greg   m     0    there   K7          7       1
31:       greg   m     0       is   K7          7       2
32:       greg   m     0       no   K7          7       3
33:       greg   m     0      way   K7          7       4
34:        sam   m     0        i   K8          8       1
35:        sam   m     0 distrust   K8          8       2
36:        sam   m     0      you   K8          8       3
37:      sally   f     0     what   K9          9       1
38:      sally   f     0      are   K9          9       2
39:      sally   f     0      you   K9          9       3
40:      sally   f     0  talking   K9          9       4
41:      sally   f     0    about   K9          9       5
42: researcher   f     1    shall  K10         10       1
43: researcher   f     1       we  K10         10       2
44: researcher   f     1     move  K10         10       3
45: researcher   f     1       on  K10         10       4
46: researcher   f     1     good  K10         10       5
47: researcher   f     1     then  K10         10       6
48:       greg   m     0      i'm  K11         11       1
49:       greg   m     0   hungry  K11         11       2
50:       greg   m     0    let's  K11         11       3
51:       greg   m     0      eat  K11         11       4
52:       greg   m     0      you  K11         11       5
53:       greg   m     0  already  K11         11       6
        person sex adult    state code element_id word_id
        person sex adult    state code element_id word_id
 1:        sam   m     0 Computer   K1          1       1
 2:        sam   m     0       is   K1          1       2
 3:        sam   m     0      fun   K1          1       3
 4:        sam   m     0      Not   K1          1       4
 5:        sam   m     0      too   K1          1       5
 6:        sam   m     0      fun   K1          1       6
 7:       greg   m     0       No   K2          2       1
 8:       greg   m     0     it's   K2          2       2
 9:       greg   m     0      not   K2          2       3
10:       greg   m     0     it's   K2          2       4
11:       greg   m     0     dumb   K2          2       5
12:    teacher   m     1     What   K3          3       1
13:    teacher   m     1   should   K3          3       2
14:    teacher   m     1       we   K3          3       3
15:    teacher   m     1       do   K3          3       4
16:        sam   m     0      You   K4          4       1
17:        sam   m     0     liar   K4          4       2
18:        sam   m     0       it   K4          4       3
19:        sam   m     0   stinks   K4          4       4
20:       greg   m     0        I   K5          5       1
21:       greg   m     0       am   K5          5       2
22:       greg   m     0  telling   K5          5       3
23:       greg   m     0      the   K5          5       4
24:       greg   m     0    truth   K5          5       5
25:      sally   f     0      How   K6          6       1
26:      sally   f     0      can   K6          6       2
27:      sally   f     0       we   K6          6       3
28:      sally   f     0       be   K6          6       4
29:      sally   f     0  certain   K6          6       5
30:       greg   m     0    There   K7          7       1
31:       greg   m     0       is   K7          7       2
32:       greg   m     0       no   K7          7       3
33:       greg   m     0      way   K7          7       4
34:        sam   m     0        I   K8          8       1
35:        sam   m     0 distrust   K8          8       2
36:        sam   m     0      you   K8          8       3
37:      sally   f     0     What   K9          9       1
38:      sally   f     0      are   K9          9       2
39:      sally   f     0      you   K9          9       3
40:      sally   f     0  talking   K9          9       4
41:      sally   f     0    about   K9          9       5
42: researcher   f     1    Shall  K10         10       1
43: researcher   f     1       we  K10         10       2
44: researcher   f     1     move  K10         10       3
45: researcher   f     1       on  K10         10       4
46: researcher   f     1     Good  K10         10       5
47: researcher   f     1     then  K10         10       6
48:       greg   m     0      I'm  K11         11       1
49:       greg   m     0   hungry  K11         11       2
50:       greg   m     0    Let's  K11         11       3
51:       greg   m     0      eat  K11         11       4
52:       greg   m     0      You  K11         11       5
53:       greg   m     0  already  K11         11       6
        person sex adult    state code element_id word_id
        act    tot    scene                                location
    1: Act1    1.1  Scene I Elsinore. A platform before the castle.
    2: Act1    1.1  Scene I Elsinore. A platform before the castle.
    3: Act1    2.1  Scene I Elsinore. A platform before the castle.
    4: Act1    2.1  Scene I Elsinore. A platform before the castle.
    5: Act1    2.1  Scene I Elsinore. A platform before the castle.
   ---                                                             
29375: Act5 1150.3 Scene II                   A hall in the castle.
29376: Act5 1150.3 Scene II                   A hall in the castle.
29377: Act5 1150.3 Scene II                   A hall in the castle.
29378: Act5 1150.3 Scene II                   A hall in the castle.
29379: Act5 1150.3 Scene II                   A hall in the castle.
                  person  died dialogue element_id word_id
    1:          Bernardo FALSE    who's          1       1
    2:          Bernardo FALSE    there          1       2
    3:         Francisco FALSE      nay          2       1
    4:         Francisco FALSE   answer          2       2
    5:         Francisco FALSE       me          2       3
   ---                                                    
29375: Prince Fortinbras FALSE       go       2007       1
29376: Prince Fortinbras FALSE      bid       2007       2
29377: Prince Fortinbras FALSE      the       2007       3
29378: Prince Fortinbras FALSE soldiers       2007       4
29379: Prince Fortinbras FALSE    shoot       2007       5

textshape documentation built on May 29, 2021, 1:07 a.m.