##### Lesson 8: The search 'for' w'if'i ##### # Setting the working directory setwd(“give the path to the folder“) list.files() # Read the data file # wifi_data = read.csv("Free_WiFi_Hotspots_09042005.csv",header=T) # print NYC 10 times for(i in 1:10) { print("NYC") } # create an empty matrix of NA in 10 rows and 1 column x <- matrix(NA,nrow=10,ncol=1) print(x) # store NYC in a matrix of 10 rows and 1 columns x <- matrix(NA,nrow=10,ncol=1) for (i in 1:10) { x[i,1] = "NYC" } print(x) # if else statement # if (x[10,1] == "NYC") {print(1)} else {print (0)} ## finding NYC LINK kiosks in Manhattan ## n = nrow(wifi_data) linknyc_hotspots = matrix(NA,nrow=n,ncol=1) for (i in 1:n) { if((wifi_data[i,4]=="MN") & (wifi_data[i,5]=="BETA LinkNYC - Citybridge")) {linknyc_hotspots[i,1] = 1} else {linknyc_hotspots[i,1] = 0} } sum(linknyc_hotspots)