R/String Manipulation

From QERM Wiki
Revision as of 00:16, 17 February 2011 by Ian (Talk | contribs)
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) print(cbind(users,userlinks),quote=F)

See also Rlogo.jpg pubchoice.R.

Personal tools