Hi, I noticed some special characters after sending. It should be: toreplace <- gsub(".*\\.pl\\?(west\\=.*south=.*)\\¶ms.*","\\1",Url1) end <- gsub(".*south=.*(\\¶ms.*)","\\1",Url1)
A.K. On Saturday, April 12, 2014 1:06 AM, arun <smartpink...@yahoo.com> wrote: HI, Not sure if this helps: df2 <- data.frame(Col1=c(68.25, 68.75, 69.25), Col2=c(24.75, 25.25, 25.75)) Url1 <- "http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=68.25&north=24.75&east=68.25&south=24.75¶ms=0%7C3B42_V7&plot_type=Time+Plot&byr=1998&bmo=01&bdy=1&eyr=2007&emo=12&edy=31&begin_date=1998%2F01%2F01&end_date=2014%2F01%2F31&cbar=cdyn&cmin=&cmax=&yaxis=ydyn&ymin=&ymax=&yint=&ascres=0.25x0.25&global_cfg=tovas.global.cfg.pl&instance_id=TRMM_V7∏_id=3B42_daily&action=ASCII+Output" toreplace <- gsub(".*\\.pl\\?(west\\=.*south=.*)\\¶ms.*","\\1",Url1) begin <- gsub("(.*\\.pl\\?).*","\\1",Url1) end <- gsub(".*south=.*(\\¶ms.*)","\\1",Url1) vec2 <- strsplit(toreplace,"&")[[1]] ##replace ".csv" with ".txt" and use write.table() if you need as text files. lapply(seq_len(nrow(df2)),function(i) { val1 <- as.vector(rep(unlist(df2[i,]),2));replaced <-do.call(paste,list(lapply(seq_along(vec2),function(i) gsub("[-+]?(\\d*[.])?\\d+",val1[i],vec2[i])),collapse="&")); UrlNew <- paste0(begin,replaced,end); res <-read.csv(UrlNew,header=TRUE,stringsAsFactors=FALSE,skip=4,sep="",check.names=FALSE); write.csv(res,file=paste0("file_",paste(val1[1:2],collapse="_"),".csv"),row.names=FALSE,quote=FALSE)}) sapply(list.files(pattern="file_"),function(x) {x1 <-read.csv(x,header=TRUE,stringsAsFactors=FALSE,check.names=FALSE); dim(x1)[1]}) #file_68.25_24.75.csv file_68.75_25.25.csv file_69.25_25.75.csv # 3652 3652 3652 ### reading the downloaded file lapply(list.files(pattern="file_"),function(x) {x1 <-read.csv(x,header=TRUE,stringsAsFactors=FALSE,check.names=FALSE); x1[5:7,]}) #[[1]] # Time(year:month:day) AccRain #5 1998:01:05 0.000 #6 1998:01:06 0.000 #7 1998:01:07 0.984 # #[[2]] # Time(year:month:day) AccRain #5 1998:01:05 0.0000 #6 1998:01:06 0.0925 #7 1998:01:07 0.2643 # #[[3]] # Time(year:month:day) AccRain #5 1998:01:05 0.0000 #6 1998:01:06 0.7043 #7 1998:01:07 0.5340 A.K. On Friday, April 11, 2014 2:38 PM, eliza botto <eliza_bo...@hotmail.com> wrote: Dear useRs, Here are three steps for downloading a file from a certain website in R. Here you see that in "URL" command (west=68.25&north=24.75&east=68.25&south=24.75) are actually the first and second column values of 1st row of a matrix called df2 (300 rows and 2 columns). more precisely, df2[1,][1]=68.25, df2[1,][2]=24.75. Is there a way that I can make a loop so that remaining rows and columns get inculcated in the link as such and then get saved at the desired mentioned location in 300 different text files? URL<-("http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=68.25&north=24.75&east=68.25&south=24.75¶ms=0%7C3B42_V7&plot_type=Time+Plot&byr=1998&bmo=01&bdy=1&eyr=2007&emo=12&edy=31&begin_date=1998%2F01%2F01&end_date=2014%2F01%2F31&cbar=cdyn&cmin=&cmax=&yaxis=ydyn&ymin=&ymax=&yint=&ascres=0.25x0.25&global_cfg=tovas.global.cfg.pl&instance_id=TRMM_V7∏_id=3B42_daily&action=ASCII+Output") destfile <- "C:\\Users\\Eliza\\Desktop\\AA\\love.txt" download.file(URL, destfile) Any suggestion? Thankyou very much in advance, Eliza [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.