0

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
Pranav_b
  • 19
  • 8

2 Answers2

0

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
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • This one worked, @Ronak. Just to clarify, the column 'Manner' also needs to be in character, right? In factor, changing the value to 'Liquid' outputs an error. Also, can you please clarify the first line of your code? I didn't run it though. – Pranav_b Mar 10 '21 at 07:53
  • Yes, column `Manner` needs to be of type character. If it is of type factor run `df$Manner <- as.character(df$Manner)` first and then run the answer. – Ronak Shah Mar 10 '21 at 07:55
  • Yes, that's what I did. Thanks again. Quick question, can I put a new value 'Nasal' in a new column based on values 'rami', 'rammi' in column 'Filename'? – Pranav_b Mar 10 '21 at 08:03
  • Create a new column `df$new_col <- NA` and then use the same code `df$new_col[grep('ramm?i', df$Filename)] <- 'Nasal'` – Ronak Shah Mar 10 '21 at 08:05
  • Understood. You saved a lot of my time. Very helpful. Bless. – Pranav_b Mar 10 '21 at 08:09
0
library(tidyverse)
my_data <- tibble::tribble(
            ~Filename,  ~Consonant,            ~Place,    ~Manner,
   "AK_kala.TextGrid", "Singleton", "Dental/alveolar", "Sonorant",
  "AK_kalla.TextGrid",  "Geminate", "Dental/alveolar", "Sonorant",
  "AK_manni.TextGrid",  "Geminate", "Dental/alveolar", "Sonorant",
   "AK_rami.TextGrid", "Singleton",        "Bilabial", "Sonorant",
  "AK_rammi.TextGrid",  "Geminate",        "Bilabial", "Sonorant",
   "AK_sune.TextGrid", "Singleton", "Dental/alveolar", "Sonorant"
  )


my_data %>%
  mutate(Manner = if_else(
    Filename %>% str_detect("kala|kalla"),
    "Liquid",
    Manner
  ))
Jon Spring
  • 55,165
  • 4
  • 35
  • 53