有没有办法根据一列的条件提取行?
Is there a way to extract rows based on condition of one column?
我希望提取第 4 行、第 11 行等的所有列。如果您查看我发布的数据,我希望提取 'xsampa' 列中 'A' 之前的行值。例如,第 4 行的所有列(出现在包含第 'xsampa' 列中的 'A' 的第 5 行之前)。我可以手动提取它们,但更好的方法肯定会节省我一些劳动力。
非常感谢你能帮助我。
Filename Speaker Consonant tdiff xsampa
1 AK_baagge.TextGrid 1 Geminate 0.23165381 B
2 AK_baagge.TextGrid 1 Geminate 0.09607762 b
3 AK_baagge.TextGrid 1 Geminate 0.15799431 A:
4 AK_baagge.TextGrid 1 Geminate 0.08753738 g:
5 AK_baagge.TextGrid 1 Geminate 0.02668823 A
6 AK_baagge.TextGrid 1 Geminate 0.12917102 e:
7 AK_baagge.TextGrid 1 Geminate 0.87323879 E
8 AK_baagi.TextGrid 1 Singleton 0.22415281 B
9 AK_baagi.TextGrid 1 Singleton 0.11448148 b
10 AK_baagi.TextGrid 1 Singleton 0.15873483 A:
11 AK_baagi.TextGrid 1 Singleton 0.09716495 g
12 AK_baagi.TextGrid 1 Singleton 0.05387364 A
13 AK_baagi.TextGrid 1 Singleton 0.10125358 i:
14 AK_baagi.TextGrid 1 Singleton 0.70685099 E
15 AK_baga.TextGrid 1 Singleton 0.78044616 B
16 AK_baga.TextGrid 1 Singleton 0.09659531 b
17 AK_baga.TextGrid 1 Singleton 0.09220461 @
18 AK_baga.TextGrid 1 Singleton 0.05159068 g
19 AK_baga.TextGrid 1 Singleton 0.13482446 A:
20 AK_baga.TextGrid 1 Singleton 0.46999388 E
正如@Jon Spring在评论中的回复,这个问题的答案是使用dplyr::lead()函数而不是lag()。这样,列 'xsampa' 中包含值 'A' 的所有行都将被过滤并生成所需的输出。
lag() 函数只会在输入后生成一行。
答案:
mydata_new<- mydata %>% filter(lead (xsampa) == "A")
输出:
Filename Speaker Consonant tdiff xsampa
1 AK_baagge.TextGrid 1 Geminate 0.08753738 g:
2 AK_baagi.TextGrid 1 Singleton 0.09716495 g
3 AK_bagga.TextGrid 1 Geminate 0.11573271 g:
4 AK_buute.TextGrid 1 Singleton 0.08538239 t`
5 AK_buutte.TextGrid 1 Geminate 0.21568940 t`:
6 AK_chaakki.TextGrid 1 Geminate 0.12341936 k:
7 AK_chape.TextGrid 1 Singleton 0.06812137 p
8 AK_chappe.TextGrid 1 Geminate 0.14723284 p:
9 AK_fati.TextGrid 1 Singleton 0.06677743 t`
10 AK_fatti.TextGrid 1 Geminate 0.13503550 t`:
11 AK_gada.TextGrid 1 Singleton 0.06472276 d_d
12 AK_gadda.TextGrid 1 Geminate 0.13475387 d_d:
13 AK_jaaddi.TextGrid 1 Geminate 0.12847036 d_d:
14 AK_jaadi.TextGrid 1 Singleton 0.06732941 d_d
15 AK_katha.TextGrid 1 Singleton 0.01338915 t_d_h
16 AK_kute.TextGrid 1 Singleton 0.04600485 t_d
17 AK_kutte.TextGrid 1 Geminate 0.15318115 t_d:
18 AK_raajegi.TextGrid 1 Singleton 0.03868537 dZ
19 AK_raajjegi.TextGrid 1 Geminate 0.10578673 dZ:
20 AK_sada.TextGrid 1 Singleton 0.05504982 d_d
我希望提取第 4 行、第 11 行等的所有列。如果您查看我发布的数据,我希望提取 'xsampa' 列中 'A' 之前的行值。例如,第 4 行的所有列(出现在包含第 'xsampa' 列中的 'A' 的第 5 行之前)。我可以手动提取它们,但更好的方法肯定会节省我一些劳动力。
非常感谢你能帮助我。
Filename Speaker Consonant tdiff xsampa
1 AK_baagge.TextGrid 1 Geminate 0.23165381 B
2 AK_baagge.TextGrid 1 Geminate 0.09607762 b
3 AK_baagge.TextGrid 1 Geminate 0.15799431 A:
4 AK_baagge.TextGrid 1 Geminate 0.08753738 g:
5 AK_baagge.TextGrid 1 Geminate 0.02668823 A
6 AK_baagge.TextGrid 1 Geminate 0.12917102 e:
7 AK_baagge.TextGrid 1 Geminate 0.87323879 E
8 AK_baagi.TextGrid 1 Singleton 0.22415281 B
9 AK_baagi.TextGrid 1 Singleton 0.11448148 b
10 AK_baagi.TextGrid 1 Singleton 0.15873483 A:
11 AK_baagi.TextGrid 1 Singleton 0.09716495 g
12 AK_baagi.TextGrid 1 Singleton 0.05387364 A
13 AK_baagi.TextGrid 1 Singleton 0.10125358 i:
14 AK_baagi.TextGrid 1 Singleton 0.70685099 E
15 AK_baga.TextGrid 1 Singleton 0.78044616 B
16 AK_baga.TextGrid 1 Singleton 0.09659531 b
17 AK_baga.TextGrid 1 Singleton 0.09220461 @
18 AK_baga.TextGrid 1 Singleton 0.05159068 g
19 AK_baga.TextGrid 1 Singleton 0.13482446 A:
20 AK_baga.TextGrid 1 Singleton 0.46999388 E
正如@Jon Spring在评论中的回复,这个问题的答案是使用dplyr::lead()函数而不是lag()。这样,列 'xsampa' 中包含值 'A' 的所有行都将被过滤并生成所需的输出。
lag() 函数只会在输入后生成一行。
答案:
mydata_new<- mydata %>% filter(lead (xsampa) == "A")
输出:
Filename Speaker Consonant tdiff xsampa
1 AK_baagge.TextGrid 1 Geminate 0.08753738 g:
2 AK_baagi.TextGrid 1 Singleton 0.09716495 g
3 AK_bagga.TextGrid 1 Geminate 0.11573271 g:
4 AK_buute.TextGrid 1 Singleton 0.08538239 t`
5 AK_buutte.TextGrid 1 Geminate 0.21568940 t`:
6 AK_chaakki.TextGrid 1 Geminate 0.12341936 k:
7 AK_chape.TextGrid 1 Singleton 0.06812137 p
8 AK_chappe.TextGrid 1 Geminate 0.14723284 p:
9 AK_fati.TextGrid 1 Singleton 0.06677743 t`
10 AK_fatti.TextGrid 1 Geminate 0.13503550 t`:
11 AK_gada.TextGrid 1 Singleton 0.06472276 d_d
12 AK_gadda.TextGrid 1 Geminate 0.13475387 d_d:
13 AK_jaaddi.TextGrid 1 Geminate 0.12847036 d_d:
14 AK_jaadi.TextGrid 1 Singleton 0.06732941 d_d
15 AK_katha.TextGrid 1 Singleton 0.01338915 t_d_h
16 AK_kute.TextGrid 1 Singleton 0.04600485 t_d
17 AK_kutte.TextGrid 1 Geminate 0.15318115 t_d:
18 AK_raajegi.TextGrid 1 Singleton 0.03868537 dZ
19 AK_raajjegi.TextGrid 1 Geminate 0.10578673 dZ:
20 AK_sada.TextGrid 1 Singleton 0.05504982 d_d