I have a datasets which contains same value.Please find the below datasets,
Parent
Child
Child
Child
Parent
Child
Child
Parent
Child
Child
Child
Child
Child
Child
Child
Child
Child
Child
I have to count the member of each parent. That means, on the 1st parent's member is 4,2nd parent's members are 3 etc.
I have already done this on excel by following formula,
=IFERROR(IF(B6="Parent",INDEX(MATCH("Parent",B7:B$23,0),1),""),COUNTA(B7:B$23)+1)`
Now, I want to achieve this things on R.
I have written following code
abc <- ifelse(ifelse(balor$Parent=="Parent", match("Parent",balor$Parent),""), count(balor,"Parent"))
but, got nothing in result.
Can you give me some hints of this problem?
Any suggestion is really appreciable.
R Code :
library(readr)
setwd("E:\\Buisness Analytics\\R\\PRACTISE")
balor <- read.csv("PersonalDeal-20180403083521.csv")
balor <- balor[,-1]
colnames(balor)[colnames(balor)=="Parent.Child"] <- "Parent"
library(plyr)
abc <-ifelse(ifelse(balor$Parent=="Parent",match("Parent",balor$Parent),""),count(balor,"Parent"))
head(abc)
# [1] NA NA NA NA NA NA