Skip to content

Instantly share code, notes, and snippets.

@klauszhang
Created May 14, 2016 10:58
Show Gist options
  • Save klauszhang/95915d49f3c10eb6ad637acae6f6405e to your computer and use it in GitHub Desktop.
Save klauszhang/95915d49f3c10eb6ad637acae6f6405e to your computer and use it in GitHub Desktop.
iterate through all userid and calculate similarity - not working, consider vectorize.
all_user_id <- unique(train$user_id)
similar_table<-list()
counter<-1
for (user in all_user_id) {
similar_user<-c(user)
current <- train[user_id == user,]
for (next_user in all_user_id[-user]) {
# calculate similarity
# this is a test
if (length(similar_user)==6) {
break
}
append(similar_user, next_user)
}
similar_table[counter]<-similar_user
counter<-counter+1
print(counter)
}
names(similar_table)<-c('user', 'U1', 'U2', 'U3', 'U4', 'U5')
list1 <- list(c(1, 2, 3, 4))
dataframe1 <- data.frame(list1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment