# What is the age of the 7th rider in the dataset?
> bike[7,2] #[1] 45 # Frequency of cycling withing the data table(bike$cyc_freq) # Daily: 47; Less than once a month: 2;Several times per month: 14; Several time s #per week: 58 #Frequency of cycling X Gender table(bike$gender,bike$cyc_freq) #Frequency of cycling for the 1st:10th - Method 1 table(bike$user_id<=10,bike$cyc_freq) #TRUE Daily: 3 #Frequency of cycling for the 1st:10th - Method 2 #Creation of object cyc_freq_10 (vector): Cycling frequency of the first 10 cyc_freq_10<-bike[bike$user_id<=10,6] #Table of contingency: Cycling frequency of the first 10 table(cyc_freq_10) #Frequency of cycling for the 1st:10th - Method 3 #Another table (from a vector: no need for $) table(bike[bike$user_id<=10,6]) #Creation of a new data frame (female), in which the gender is female AND (&) th e #cycling distance is Less than once a month female<-bike[bike$gender=='F'&bike$cyc_freq=='Less than once a month',] View(female) #Speed of the first female who rides the bicycle less than once a month > female[1,9] #1) Find the number of students in the dataset (bike) table(bike$student) #14 students #2) Pull out the student data into a separate dataframe for analysis. student<-bike[bike$student==1,] View(student) #3) Find how often the students ride. #Method 1: no additional vector (that is, from student dataset) table(student$cyc_freq) #Method 2: additional vector freq_stud freq_stud<-student[,6] View(freq_stud) table(freq_stud) #Method 3 :no need for vector student: crossing table table(bike$student,bike$cyc_freq)
#Method 4: no need for vector student: crossing table:
#use of logical operators whithin table function table(bike$student==1,bike$cyc_freq) #4) Find the average distance ridden #Method 1: vector distance from dataset student distance<-student$distance #Method 2: another line for vector distance from dataset student distance<-student[,7] #Method 3: directly from dataset bike distance<-bike[bike$student==1,7] #Method 4: directly from dataset bike II distance<-bike[bike$student==1,]$distance View(distance) mean(distance) #6.257857
(Lecture Notes in Social Networks) Fazli Can, Tansel Özyer, Faruk Polat (Eds.) - State of The Art Applications of Social Network Analysis-Springer International Publishing (2014)