본문 바로가기
언어/R

sqlite3

by newlibra 2023. 2. 11.

library(DBI)
library(RSQLite)

con <- dbConnect(SQLite(), dbname = "test_sqlte.sqlite")
dbSendQuery(con, "CREATE TABLE iris_db (
            Sepal_Length REAL,
            Sepal_Width REAL, 
            Petal_Length REAL, 
            Petal_Width REAL, 
            Species TEXT
            )")

dbExistsTable(con, "iris_db")
dbListTables(con)

dbSendQuery(con, "INSERT INTO iris_db
                  (Sepal_length, Sepal_width, Petal_length, Petal_width, Species)
                  VALUES
                  (5.1, 3.5, 1.4, 0.2, 'setosa')")

dbGetQuery(con, "SELECT * FROM iris_db")

dbWriteTable(con, "iris_db_2", iris)

dbGetQuery(con, "SELECT * FROM iris_db_2") 

dbRemoveTable(con, "iris_db")
dbRemoveTable(con, "iris_db_2")

dbDisconnect(con)

'언어 > R' 카테고리의 다른 글

bond  (0) 2023.03.05
script  (0) 2023.02.20
sqlite 2  (0) 2022.12.04
postgres  (0) 2022.12.03
sqlite  (0) 2022.11.30