R/String Manipulation
From QERM Wiki
(Difference between revisions)
m (added <NOWIKI> </NOWIKI> to get R code formatted correctly) |
(added link to new function) |
||
Line 13: | Line 13: | ||
print(cbind(users,userlinks),quote=F) | print(cbind(users,userlinks),quote=F) | ||
</NOWIKI> | </NOWIKI> | ||
+ | |||
+ | |||
+ | See also {{Rcode|pubchoice.R|pubchoice.R}}. | ||
+ | |||
+ | |||
+ | [[Category: R tips]] |
Revision as of 00:16, 17 February 2011
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.