简体   繁体   English

从长格式数据中获取非 na 数据

[英]Get non-na data from long format data

username,Phase,compound,Time,agegroup
000000ceans,6,0.1531,0.85,YA
000000ceans,1,,0,
000000ceans,2,,0.17,
000000ceans,3,,0.34,
000000ceans,4,,0.51,
000000ceans,5,,0.68,
000000ceans,7,,1.02,
00000codename,5,0.4588,0.68,YA
00000codename,1,,0,
00000codename,2,,0.17,
00000codename,3,,0.34,
00000codename,4,,0.51,
00000codename,6,,0.85,
00000codename,7,,1.02,
0000lailai,6,-0.2023,0.85,YA
0000lailai,1,,0,
0000lailai,2,,0.17,
0000lailai,3,,0.34,
0000lailai,4,,0.51,
0000lailai,5,,0.68,
0000lailai,7,,1.02,

I have a data frame like this (~ a million row), each username has 7 rows (0-6Nas in the compound).我有一个这样的数据框(~一百万行),每个用户名有 7 行(复合中的 0-6Nas)。 I hope to have a data frame with all the users who have 0-2Nas (<=2) in the compound.我希望与所有在化合物中具有 0-2Nas (<=2) 的用户有一个数据框。

The output will be something like this output 将是这样的

username   phase      compound      agegroup   Time
a           1            0.1          YA       assigned according to phase
a           2            0.2          YA       assigned according to phase
a           3            0.3          YA       assigned according to phase
a           4            0.4          YA       assigned according to phase
a           5            0.5          YA       assigned according to phase
a           6            NA           YA       assigned according to phase
a           7            Na           YA       assigned according to phase
b
b
b
df %>%
  group_by(username)%>%
  filter(sum(is.na(compound))<=2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM