I am trying to reshape the data but with some conditions. The data looks like below. similarly there will be more ID which are repeating
S.No Count ID Type
1 135 350 A
2 114 350 A
3 84 350 A
4 80 350 A
5 19 350 A
6 8 350 A
7 21 350 A
8 88 350 B
9 111 350 B
10 46 350 B
11 108 350 B
12 19 352 A
13 117 352 A
14 167 352 B
And I need to convert it like below.
S.No ID Type Count_type B Count_typeA_less than Count_typeA
max(count_type B) high than
max(count_type B)
1 350 B 88,111,46,108 84,80,19,8,21 135,114
2 352 B 167 19,117 NA
Count_typeA_Less than max(count_type B) = count of type A which are less than maximum number of count_type B
Count_typeA_high than max(count_type B) = count of type A which are higher than the maximum number of count_type B
I tried with the dplyr and reshape. I could not achieve this.
--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.
Expected_output= data %>%
group_by(id, Type) %>%
mutate(Count_of_B = paste(unlist(count[Type=="B"]), collapse = ","))%>%
mutate(Max_of_count_B = ifelse(Type == "B", max(count[Type == "B"]),max(count[Type == "A"]))) %>%
mutate(count_type_A_lesser = ifelse (Type=="B",(paste(unlist(count[Type=="A"]) < Max_of_count_B[Type=="B"], collapse = ",")), "NA"))%>%
mutate(count_type_A_higher = ifelse(Type=="B",(paste(unlist(count[Type=="A"]) > Max_of_count_B[Type=="B"], collapse = ",")), "NA"))