Hi all,
I have a data frame like this-
Category | Sub category | Option |
---|---|---|
A | A_1 | Q1 |
A | A_2 | Q2 |
A | A_3 | Q3 |
B | B_1 | Q4 |
B | B_2 | Q5 |
C | C_1 | Q6 |
C | C_2 | Q7 |
D | D_3 | Q8 |
D | D_4 | Q9 |
I want the output as such the data gets filtered based on Category basis . Like when I select "A", the output should be-
A_1
A_2,
A_3.
and subsequently for all Category.
I tried using-
fct<- function(quest)
{
quest<-c(1:nrow(df))
for(i in 1:nrow(df))
{
if(df$Category[i]==df$Category[i+1])
{
quest[i]<- print(paste(df$`Sub-Category`[i]))
}
}
return(quest)
}
opt<- fct(quest)
How to get this?