Skip to content

Commit

Permalink
get_data_frame_of_words_from_urls関数のfor文をmapplyに置き換えて、高速化した。
Browse files Browse the repository at this point in the history
  • Loading branch information
syou6162 committed Aug 17, 2008
1 parent 46445e8 commit 7e7817b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 4 additions & 4 deletions collective.R
Expand Up @@ -11,7 +11,6 @@ blog.write_blogs_from_opml(blog.get_blogs_from_opml)
return(d)
}


#blogとキーワードの行列を生成する(本当はデータフレームになっている)
get_data_frame_of_words_from_urls <- function(urls){
extract_meisi_from_blog <- function(url){
Expand All @@ -35,12 +34,13 @@ blog.write_meisi_from_blog(blog.extract_meisi_from_blog(%q[",url,"]))
}
return(a)
}

a <- make_lists_of_words_from_urls(urls$url)
#Iは因子化を防ぐための操作
d <- data.frame(words=I(unique(unlist(mapply(names,a)))))
for(i in seq(length(a))){
d[,i+1] <- as.numeric(mapply(function(x){ifelse(!is.na(a[[i]][x]),a[[i]][x],0)},d$words))
}


d <- cbind(d,mapply(function(i){as.numeric(mapply(function(x){ifelse(!is.na(a[[i]][x]),a[[i]][x],0)},d$words))},seq(length(a))))
#keywordをrow.namesにして、データフレームから出しておく
row.names(d) <- d$words
d$words <- NULL
Expand Down
13 changes: 4 additions & 9 deletions main.R
Expand Up @@ -3,23 +3,18 @@ source("./collective.R")

urls <- get_blogs_from_opml()
urls
names(d)
d <- get_data_frame_of_words_from_urls(urls)
cor(d[,1:5])
symnum(cor(d[,1:5]))
str(d)

save


save(d, file = "d.Rdata")





apply(add_frag(urls,flags)$flag,1,sum)



load("d.Rdata")


flags <- c(
Expand All @@ -33,5 +28,5 @@ flags <- c(
"http://www.geekpage.jp/rss.php"
)


apply(add_frag(urls,flags)$flag,1,sum)

0 comments on commit 7e7817b

Please sign in to comment.