Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Modul

This document discusses connecting to a MySQL database in R, running SQL queries to select and group data, manipulating the returned data, and closing the database connection. SQL queries are constructed and sent to the database to retrieve customer phone number patterns and names. The returned data is then cleaned by removing 'ir' from names before the connection is closed.

Uploaded by

Mutia Ka
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Modul

This document discusses connecting to a MySQL database in R, running SQL queries to select and group data, manipulating the returned data, and closing the database connection. SQL queries are constructed and sent to the database to retrieve customer phone number patterns and names. The returned data is then cleaned by removing 'ir' from names before the connection is closed.

Uploaded by

Mutia Ka
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

library(openxlsx)

library(writexl)
library(RMySQL)

sql <- "SELECT pola_no_telepon, length(pola_no_telepon) as panjang_text, count(*)


as jumlah_data from data_pelanggan group by pola_no_telepon"

#Membuka koneksi
con <- dbConnect(MySQL(), user="root", password="Muti@2121", host="localhost",
dbname="mydb", port=3306)

#Konstruksi SQL
sql <- "SELECT kode_pelanggan, nama_lengkap FROM data_pelanggan WHERE nama_lengkap

#Mengirimkan query
rs <- tryCatch(dbSendQuery(con, sql), finally = print ("query ok"))

#Menggambil data
data.pelanggan <- fetch(rs, n=-1)
data.pelanggan

data.pelanggan$nama_lengkap<-
gsub("\\bir\\b","",data.pelanggan$nama_lengkap,ignore.case = TRUE)

#Menutup Koneksi
all_cons <- dbListConnections(MySQL())
for(con in all_cons) dbDisconnect(con)

You might also like