[R] alternating element in url

frauke fhoss at andrew.cmu.edu
Tue Feb 7 02:05:25 CET 2012


Hey everybody, 

it would be really appreciate if you knew the solution to the following
problem. 

I am trying to load data from the internet into R without having to save
them. However, I need to acess a different website for each dataset. So I
want to alternate an element in the URL. Eventually, I want to fill a 3
dimensional matrix/array where each slice is a two-dimensional matrix from
the corresponding website.  For example:

###############################################################################
ID=c(1,5,6,8,10)                      #ID of dataset/website, each dataset
contains a matrix [4x6]
data=array(numeric(0),length(ID) ,4,6)   #empty array [5x4x6]

for (kk in 1:length(ID)) {
url  <-cat("http://ministry.gov/case",ID[kk],"_agencyk")   #should return 
"http://ministry.gov/case1_agencyk" for kk=1, etc.
import.data <-   as.matrix(  read.table(url)  )

for (tt in 1:4) {

for (mm in 1:6) {
data[kk,tt,mm] <- import.data[tt,mm]
}}}
################################################################################

I got all to work, but the problem is assembling the URL.  In the code above
url just returns NULL.  Once that is solved I have trouble because
read.table needs the URL to be in "". If I put read.table("url") R wont
recognize it as the url I defined earlier. But I also do not know how to use
cat() to get " at beginning and end. 

If I am approaching this in a totally dorky way (likely...), please let me
know, too. 

Thank you!! Frauke

Frauke Hoss
PhD student Carnegie Mellon



--
View this message in context: http://r.789695.n4.nabble.com/alternating-element-in-url-tp4363423p4363423.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list