R/String Manipulation

From QERM Wiki
Revision as of 00:12, 4 April 2012 by Ian (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Here's an example that uses somes string manipulation functions extract some information from a file.

 x = readLines("http://wiki.cbr.washington.edu/qerm/index.php/Special:Listusers")
 x2 = grep("User:", x, value=T)
 starts = as.numeric(gregexpr("/qerm/index.php/User:", x2)[[1]])
 ends   = as.numeric(gregexpr("\" title=\"User:",      x2)[[1]])-1
 nusers = length(starts)
 users = rep(NA,nusers)
 userlinks = rep(NA,nusers)
 for(i in 1:nusers) userlinks[i] = paste("http://wiki.cbr.washington.edu",substr(x2,starts[i],min(ends[ends>starts[i]])),sep="")
 users = sub('http://wiki.cbr.washington.edu/qerm/index.php/User:','',userlinks)

See also Rlogo.jpg pubchoice.R.

Personal tools