Something like this may get you started
library("igraph")
df<- data.frame(A=0:7, B=c(rep(NA,3), 0, 1, 3, 7, 2)) # Assuming this is your
data
b<- as.matrix(df)
print(b)
# A B
#[1,] 0 NA
#[2,] 1 NA
#[3,] 2 NA
#[4,] 3 0
#[5,] 4 1
#[6,] 5 3
#[7,] 6 7
#[8,] 7 2
z<- graph.edgelist(na.omit(b))
neighborhood(z, Inf, mode = "in")
#[[1]]
#[1] 0 3 5
#
#[[2]]
#[1] 1 4
#
#[[3]]
#[1] 2 7 6
#
#[[4]]
#[1] 3 5
#
#[[5]]
#[1] 4
#
#[[6]]
#[1] 5
#
#[[7]]
#[1] 6
#
#[[8]]
#[1] 7 6
Hope this helps
Allan
On 24/08/10 19:28, Mike Rhodes wrote:
>
>
>
> Dear R Helpers,
>
>
> I am a newbie and recently got introduced to R. I have a large database
> containing the names of bank branch offices along-with other details. I am
> into Operational Risk as envisaged by BASEL II Accord.
>
>
> I am trying to express my problem and I am using only an indicative data
> which comes in coded format.
>
>
>
>
> A (branch) B (controlled by)
>
>
> 144
> 145
> 146
> 147 144
> 148 145
> 149 147
> 151 146
> ...... .......
>
> ...... .......
>
>
> where 144's etc are branch codes in a given city and B is subset of A.
>
>
>
>
> If a branch code appearing in "A" also appears in "B" (which is paired with
> some otehr element of A e.g. 144 appearing in A, also appears in "B" and is
> paired with 147 of "A" and likewise), then that means 144 is controlling
> operations of bank office 147. Again, 147 itself appears again in B and is
> paired with bank branch coded 149. Thus, 149 is controlled by 147 and 147 is
> controlled by 144. Likewise there are more than 700 hundred branch name codes
> available.
>
>
> My objective is to group them as follows -
>
>
> Bank Branch
>
>
> 144 147 149
>
>
> 145
>
>
> 146 151
>
>
> 148
> .....
>
>
> or even the following output will do.
>
>
> 144
> 147
> 149
>
>
> 145
>
>
> 146
> 151
>
>
> 148
> 151
> ......
>
>
> I understand I should be writing some R code to begin with which I had tried
> also but as of now I am helpless. Please guide me.
>
>
> Mike
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.