1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
library(RODBC) # Connect to the database while mentioning database name explicitly. channel <- odbcDriverConnect("driver=SQL Server;server=ServerName;database=DatabaseName") # Change all Columns to Strings to avoid errors for (col.name in colnames(Students)) { Students[,col.name] <- as.character(Students[,col.name]) } # Drop the table sqlDrop(channel, 'idin.Students2') # Write the table into the database sqlSave(channel, Students, tablename = 'idin.Students2', append = FALSE, rownames = FALSE) close(channel) |
R
R: Reading from SQL Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
library(RODBC) channel <- odbcDriverConnect("driver=SQL Server;server=ServerName") # Request information on the ODBC connection odbc.info <- odbcGetInfo(channel) getSqlTypeInfo(odbc.info[1]) # Read data query <- "SELECT * FROM Database.dbo.Student AS Student LEFT JOIN Database.dbo.Teacher AS Teacher ON Teacher.id=Student.teacher_id WHERE Student.gpa<'60' ORDER BY Student.gpa DESC" Students <- sqlQuery(channel, query) close(channel) |
R: Saving a Multiple-Column Boxplot into PDF
1 2 3 4 5 6 7 8 9 10 |
n_audio = length(levels(tlx$audio)) par(mfrow = c(1, n_audio)) for (i in levels(tlx$audio)) { boxplot(tlx_overall~guidance, outline = FALSE, data = subset(tlx, audio==i), main = "All Data", xlab = i, ylab="TLX (Overall)", cex = 1, cex.lab = 1, cex.main = 1, cex.axis = 1, pch = 23, col = 3, lwd=.5) } dev.copy2pdf(device = quartz, file = "tlx_per_audio_x_guidance.pdf") dev.off (); |