Profiling & Simulation Aim:: Pre-Lab Discussion Theory
Profiling & Simulation Aim:: Pre-Lab Discussion Theory
SIMULATION
AIM:
Pre-Lab Discussion
THEORY
Rprof() keeps track of the function call stack at regularly sampled intervals and tabulates
how much time is spent inside each function. By default, the profiler samples the function
call stack every 0.02 seconds.
Rprof() function, everything that you do from then on will be measured by the
profiler. Therefore, you usually only want to run a single R function or expression once you
turn on the profiler and then immediately turn it off. The reason is that if you mix too many
function calls together when running the profiler, all of the results will be mixed together
and you won’t be able to sort out where the bottlenecks are. In reality, I usually only run a
single function with the profiler on.
The raw output from the profiler looks something like this. Here I’m calling
the lm() function on some data with the profiler running.
X<-rnorm(10)
y<-rnorm(10)
## lm(y ~ x)
sample.interval=10000
PROGRAM:
## Elapsed time > user time
system.time(readLines("http://www.jhsph.edu"))
+ i <- 1:n
+ 1 / outer(i - 1, i, "+")
+}
> system.time(svd(x))
X<-rnorm(10)
y<-rnorm(10)
## lm(y ~ x)
sample.interval=10000
OUTPUT:
set.seed(20)
x <- rnorm(100)
y <- 0.5 + 2 * x + e
summary(y)
plot(x, y)
set.seed(10)
y <- 0.5 + 2 * x + e
plot(x, y)
RESULT:
Thus the program to perform SQL operation in R was successfully executed.
QUERY DATA USING SQL AND R
AIM:
ALGORITHM:
Step 1: at first we need to connect the mysql server to the r script by installing the
library called RMySQL.
Step 2: after connection we need to create the table using the dbSentQuery function.
Step 3: after creation of table in database we need to get values from the user to
insert into the sql table.
Step 3: then we need to insert the data into the table using dbSentQuery function.
Step 4: after insertion we need to get the values of the table from database using
dbGetQuery.
PROGRAM:
library(RMySQL)
dbname = "database_name",
host = "localhost",
port = 3306,
user =
"root"
if(val=='S'){
mark3:"))
}else{
break
stud_db<-dbGetQuery(con,'select * from
stud') stud_db
OUTPUT:
1 xxx 99 100 88
2 yyy 88 89 78
3 zzz 56 67 79
RESULT: