This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
bdlibre [2017/02/20 14:42]
glaroc [Introduction à la gestion des bases de données avec des logiciels libres]
bdlibre [2017/02/21 15:35]
glaroc [Lier R avec PostgreSQL]
Line 949: Line 949:
 lakesqc <- dbGetQuery(con,"​SELECT * FROM lakes WHERE province='​QUEBEC'"​) lakesqc <- dbGetQuery(con,"​SELECT * FROM lakes WHERE province='​QUEBEC'"​)
 hist(lakes$tmean_an) hist(lakes$tmean_an)
 +===== Using the dplyr package=====
 +<file rsplus>
 +src<​-src_postgres(dbname="​workshop",​host="​localhost",​ port="​5432",​user="​your_username",​password="​your_password"​)
 +lakes <- tbl(src, "​lakes"​) # Define lakes table
 +lakes_qc<​-filter(lakes,​ province ​ %=% '​QUEBEC'​) # Select lakes in Quebec
 +prov_tmean<​-summarise(group_by(lakes,​ province), mean(tmean_an)) # Mean annual temperature per province
 +prov_tmean=collect(prov_tmean) # Transfer result to standard R data frame
 +lakes_qc2<​-tbl(src,​ sql("​SELECT * FROM lakes WHERE province='​QUEBEC'"​)) #Perform any SQL statement
 </​file>​ </​file>​