Loading data in R from internet
Importing a *. txt file from the Internet
Import decathlon.txt file from STHDA web site: :
Code R :
data=read.table(file="https://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('https://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='https://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