R/String Manipulation
From QERM Wiki
(Difference between revisions)
(added link to new function) |
m (replaced <NOWIKI> with <pre> to fix bad formatting) |
||
Line 1: | Line 1: | ||
Here's an example that uses somes string manipulation functions extract some information from a file. | Here's an example that uses somes string manipulation functions extract some information from a file. | ||
− | < | + | <pre> |
x = readLines("http://wiki.cbr.washington.edu/qerm/index.php/Special:Listusers") | x = readLines("http://wiki.cbr.washington.edu/qerm/index.php/Special:Listusers") | ||
x2 = grep("User:", x, value=T) | x2 = grep("User:", x, value=T) | ||
Line 12: | Line 12: | ||
users = sub('http://wiki.cbr.washington.edu/qerm/index.php/User:','',userlinks) | users = sub('http://wiki.cbr.washington.edu/qerm/index.php/User:','',userlinks) | ||
print(cbind(users,userlinks),quote=F) | print(cbind(users,userlinks),quote=F) | ||
− | </ | + | </pre> |
Latest revision as of 00:12, 4 April 2012
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 pubchoice.R.