-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_cast.R
37 lines (29 loc) · 954 Bytes
/
get_cast.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
library(XML)
library(plyr)
#concatenate musical titles and dates
Musical <- paste0(as.character(output$musicals), "(", as.character(output$dates), ")")
#concatenate artist name and id
Artist <- paste0(as.character(output$name), "(", as.character(output$id), ")")
#combine the two vectors into a data frame.
sorted <- cbind(Musical, Artist)
sorted <- as.data.frame(sorted)
#sort the data frame by Musical
sorted <- sorted[order(sorted$Musical),]
result <- {}
i <- 1
while (i < dim(sorted)[1])
{
j <- i+1
#row = musical, actor1, actor2, actor3, ..., actorN
row <- as.character(sorted[i,1])
row <- append(row, as.character(sorted[i,2]))
while (sorted[j,1] == sorted[i,1])
{
row <- append(row, as.character(sorted[j,2]))
j <- j+1
}
i <- i + length(row)-1
#save each row in result
result <- rbind.fill(as.data.frame(result), as.data.frame(t(row)))
}
write.csv(result, "result.csv")