Articles - R

Loading data in R from internet

  |   6272  |  Post a comment  |  R

Importing a *. txt file from the Internet



Import decathlon.txt file from STHDA web site: :

Code R :
 
data=read.table(file="http://www.sthda.com/upload/decathlon.txt", 
                       header=T, row.names=1, sep="\t") #Importation des données
print(data) # Print the data
 



Load .rdata file from internet



To do this, you must first create a connection using the R url function. You can then load the connexion.

Code R :
 
con<-url('http://www.sthda.com/upload/decathlon.rdata') # Create connexion
load(con) #Load the data
close(con) #close connexion
print(d) # Print the data
 


Download file from internet using R



To download a file from the Internet with R, we can use the function : download.file :

Code R :
 
download.file(url='http://www.sthda.com/upload/decathlon.rdata', 
                         destfile ="decathlon.rdata")
 


The file will be downloaded and saved in the current directory with the name decathlon.rdata