R: Looping through Grouped ID

517 views Asked by At

I am currently trying to create a network for each grouped data I have. It is a large dataframe, so I am hoping to use a for loop to create all of them.

The structure of my code for building a single network looks something like this:

p1603 <- multipath[multipath$visitlink== "p1603",]
g1603 <- graph.data.frame(p1603[,c(1,2)],directed=FALSE)
V(g1603)$hospnet <- p1603$hospnet
plot(g1603)

In the above case, p1603 an example of an ID in the visitlink column of the multipath database that I want to loop through. Each visitlink contains several rows of data, so I would want to loop through each visitlink group. All IDs start with p and is followed by a series of random numbers.

1

There are 1 answers

0
ltong On

I was able to figure it out.

To loop through a group, I start with the following:

for (i in unique(multipath_test$visitlink)){
...
}