I'm working on a web scraping project. Each webpage has a table with 101 rows. The main chunk of code shows the initial attempt to pull info from the webpage that pulls values from a different column into an empty vector that meet conditions being met of a different column.
The append call is not working, and I'm not sure what's going on. Could someone help guide me in the right direction, and explain to me why that particular way works? I appreciate any thoughts or ideas.
wl_record <- c()
dateof <- c()
con_1 <- str_detect(misawa$X4, "Mitsuharu Misawa defeats")
con_2 <- str_detect(misawa$X4, "defeats Misuharu Misawa")
for(i in misawa$X4){
if (str_detect(i, "Mitsuharu Misawa defeats") == TRUE) {
dateof[con_1] <- misawa$X2
wl_record[con_1] <- "win"
} else if(str_detect(i, "defeats Mitsuharu Misawa") == TRUE) {
append(dateof[con_1], misawa$X2)
append(wl_record[con_1], misawa$X2) <- "loss"
}
}
*EDIT An excerpt from the misawa data frame is below. The columns are X1 = record number, X2 = date, X3 = blank, X4 = match information. The string detect is important, as I'm just looking to pull singles match data. "defeat" indicates a tag match, while "defeats" indicates a singles match:
X1 X2 X3 X4
901 10.12.2000 Daisuke Ikeda & Mitsuharu Misawa defeat Kenta Kobashi & Takeshi Rikio (21:55)NOAH The Final Navigation - Tag 7 - Event @ Act City Hamamatsu in Hamamatsu, Shizuoka, Japan
902 08.12.2000 Takao Omori & Yoshihiro Takayama defeat Mitsuharu Misawa & Yoshinari Ogawa (18:41)NOAH The Final Navigation - Tag 6 - Event @ Miyagi Sports Center in Sendai, Miyagi, Japan
903 07.12.2000 Mitsuharu Misawa & Yoshinari Ogawa defeat Jun Akiyama & Takeshi Morishima (15:34)NOAH The Final Navigation - Tag 5 - Event @ Odate Citizen Gymnasium in Odate, Japan
The result of the for loop is a vector that is equal in length to the original data frame. The rows not meeting the condition show up as NA. The goal is to append each vector until I have all of the data, then combine dateof
and wl_record
into a dataframe that the NA's will then be removed from.