rdplyrphonetics

Is there a function to replace specific values in a column based on condition from another column?


I wish to replace the present value in column 'Manner' for all the words containing, 'kala', 'kalla' in column 'Filename' (the first two initials denote the Speaker) from "Sonorant' to "Liquid".

My idea is that it could be performed through 'dplyr' (probably 'grep') but don't know how to. This can be done in MS Excel but it will take a great amount of time by doing it manually.

Any help will be great. Thanks in advance.

Some of my data here:

Filename Consonant           Place   Manner
9   AK_kala.TextGrid Singleton Dental/alveolar Sonorant
10 AK_kalla.TextGrid  Geminate Dental/alveolar Sonorant
14 AK_manni.TextGrid  Geminate Dental/alveolar Sonorant
15  AK_rami.TextGrid Singleton        Bilabial Sonorant
16 AK_rammi.TextGrid  Geminate        Bilabial Sonorant
20  AK_sune.TextGrid Singleton Dental/alveolar Sonorant

Solution

  • You can check for pattern in Filename column and turn the Manner column to 'Liquid'.

    df$Manner[grep('kall?a', df$Filename)] <- 'Liquid'
    #Maybe this is more clear
    #df$Manner[grep('kala|kalla', df$Filename)] <- 'Liquid'
    df
    
    #            Filename Consonant           Place   Manner
    #9   AK_kala.TextGrid Singleton Dental/alveolar   Liquid
    #10 AK_kalla.TextGrid  Geminate Dental/alveolar   Liquid
    #14 AK_manni.TextGrid  Geminate Dental/alveolar Sonorant
    #15  AK_rami.TextGrid Singleton        Bilabial Sonorant
    #16 AK_rammi.TextGrid  Geminate        Bilabial Sonorant
    #20  AK_sune.TextGrid Singleton Dental/alveolar Sonorant