Displaying 20 results from an estimated 2360 matches for "dt".
Did you mean:
gdt
2008 Jul 28
2
Help with a loop
...matic. The
problem is that the output from ts1, ts2, and so on is a vector with more
than one value, so I do not know how to solve this.
Thanks
Prenewbie
The code is the following:
duration<-c(750, 8940,17180, 8693,10100, 7990,24820, 6770,
7390,8450,18400,16252,6080,11030)
tmax<-0
dt<-0
for (m in 1:14)
{
tmax[m]<-duration[m]
dtmin<-969
dtmax<-9884
i<-1
dt[m]<-round(runif(1,dtmin,(tmax[m]-1)))}
ts<-c(1)
ts1<-ts
ts2<-ts1
ts3<-ts1
ts4<-ts1
ts5<-ts1
ts6<-ts1
ts7<-ts1
ts8&l...
2017 Nov 01
3
repeat a function
I want to populate the matrix prb through the function HWMProb <- function (a,j,dt) that encapsulates different functions (please see code below), using j= 0:2 for each j.
It only populates prb if I specify each function independently in the global environment and then run the loop with the iF statement, as per below.
for (j in 0:2) {
if (j==0) {
prb["0","1&...
2017 Nov 02
2
repeat a function
...l depend on my node and is not always the same per row (e.g. if N> jmax, jmax being defined in another function)
I found a workaround. Please see below.
Thereafter I want to optimize this function. Hopefully it works.
Many thanks,
Eric
HWMProb <- function(N) {
ProbUP<- function( a, j, dt) 1 / 6 + ((j ^ 2 * Mfactor(a, dt) ^ 2 + j * Mfactor(a, dt)) / 2) ######### Probability X going up
ProbMID<- function(a, j, dt) 2 / 3 - (j ^ 2 * Mfactor(a, dt) ^ 2) ######## Probability X going middle
ProbDWN<-function( a, j, dt) 1 / 6 + ((j ^ 2...
2017 Nov 03
0
repeat a function
...t if you want increase size of your matrix?
E.g. you use function ProbUP once for row "0" and than for rows different from jmax (if I correctly understand your code). Use of any function depends on two parameters (row and column, let them call u and v)
> ProbUP<- function( a, j, dt) 1 / 6 + ((j ^ 2 * Mfactor(a, dt) ^ 2 + j * Mfactor(a,
> dt)) / 2) ######### Probability X going up
> ProbMID<- function(a, j, dt) 2 / 3 - (j ^ 2 * Mfactor(a, dt) ^ 2)
> ######## Probability X going middle
> ProbDWN<-function( a, j, dt) 1 / 6 + ((j ^ 2 * Mfactor(a, dt...
2017 Nov 02
0
repeat a function
...wonder why would it be necessary to use for cycle for what seems to be simple table. Everything seems quite deterministic.
Basically you have combination of rows (-2,-1,0,1,2) and columns -1,-,1.
expand.grid(u=-2:2, v=-1:1)
for each row you can than use one function with parameters u, v and a and dt.
After you calculate vector of results, you can easily transform it to matrix by setting dim argument to it.
Cheers
Petr
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of
> Eric.Pueyo at avivainvestors.com
> Sent: Wednesday, November 1,...
2013 Mar 19
1
How can I eliminate a loop over a data.table?
I've two data.tables as shown below:
***
N = 10
A.DT <- data.table(a1 = c(rnorm(N,0,1)), a2 = NA))
B.DT <- data.table(b1 = c(rnorm(N,0,1)), b2 = 1:N)
setkey(A.DT,a1)
setkey(B.DT,b1)
***
I tried to change my previous data.frame implementation to a
data.table implementation by changing the for-loop as shown below:
***
for (i in 1:nrow(B.DT)) {...
2012 Nov 12
3
arrange data
...like to extract november and december data only. I would also like to do column bind for november and december, therefore I would like to delete 31 December from december data so that the length of november and december are the same. Hope somebody can help me. I tried this below:
> kuantan.dt.1 <- kuantan.dt[(kuantan.dt$Bulan >=11) & (kuantan.dt$Bulan <= 12),]
> head(kuantan.dt.1) ; tail(kuantan.dt.1)
Tahun Bulan Hari Jumlah.Hujan.mm.
305 71 11 1 0.0
306 71 11 2 16.3
307 71 11 3 0.0
308 71 11 4...
2009 May 07
1
data transformation using gamma
Hi R-users,
I have this code to uniformise the data using gamma:
> length(dp1)
[1] 696
> dim(dp1)
[1] 58 12
> dim(ahall)
[1] 1 12
> dim(bhall)
[1] 1 12
> trans_dt <- function(dt,a,b)
+ { n1 <- ncol(dt)
+ n2 <- length(dt)
+ trans <- vector(mode='numeric', length=n2)
+ dim(trans) <- dim(dt)
+ for (i in 1:n1)
+ { dt[,i] <- as.vector(dt[,i])
+ trans[,i] <- transform(dti,newdt=pgamma(dti,shape= a[1,i],scale=b[1,i]))...
2006 May 20
3
sapply and Date objects
This is probably a dumb question, but I cannot figure it out. Why does
this happen?
dt <- as.Date("1954-02-01")
> as.character(dt)
[1] "1954-02-01"
> sapply(c(dt), as.character)
[1] "-5813"
Thanks.
FS
2010 Sep 24
1
color of lines while printing through for loop
...number of lines, but I don't know how to implement this into my
loop.
Is this possible?
This is my script:
__________________________________________________________________
###creating two emty vectors and opening a graphics window
x <- vector()
y <- vector()
plot(x,y, xlim = c(pheno.dt$year[1],pheno.dt$year[nrow(pheno.dt)]), ylim
= c(min(pheno.dt$julian, na.rm = TRUE),max(pheno.dt$julian, na.rm =
TRUE)), xlab = "Year", ylab = "Julian Day")
###setting up colors
sp_pheno.unique <- unique(pheno.dt$sp_pheno)
colors <- seq(1,200,1)
####printloop
for...
2015 Mar 10
3
como hacer una operacion con data.table
...r
a usar data.table porque normalmente tengo que manejar una buena cantidad
de datos
ahora necesito hacer un calculo simple, para el que antes usaba ciclos FOR,
pero quiero aprovechar las ventajas de data.table
mi preguna es como podria calcular, por ejemplo, la columna 2 de un
data.table llamada DT si el valor de la primera columna es una serie de 1 a
10, y la celda de la fila m de la segunda columna es igual al valor de la
celda m de la primera columna menos la celda m-1 de la primera columna.
me explico ??
si fuera un ciclo con data.frame lo haria asi:
i <- 2
for (...
2006 Nov 20
2
problem with loop to put data into array with missing data for some files
...#decode the grib
cmd <- paste("/usr/local/bin/wgrib ", outfile, "| grep \":PRATE:\" |
/usr/local/bin/wgrib", outfile, "-i -V -text -o /tmp/wgrib.output")
status <- system(cmd, intern=T)
#extract metadata needed for working with julian dates:
dt <- unlist(strsplit(status[1], " "))[3]
dt.yr <- as.numeric(substr(dt, 1,4))
dt.mon <- as.numeric(substr(dt, 5,6))
dt.day <- as.numeric(substr(dt, 7,8))
dt.hr <- as.numeric(substr(dt, 9,10))
dt.jul <- julian(dt.mon, dt.day+(dt.hr/24), dt.yr)
parameter <- unlist...
2010 Aug 20
2
Problem with POSIXct in ave
Hi,
I am having trouble using the ave function with a POSIXct object. For
example:
x<-Sys.time()+0:9*3600
dat<-data.frame(id=rep(c('a','
b','c'),each=10),dt=rep(x,3),i=rep(1:10,3))
dat
# This is what I want to do:
dat$time.elapsed<-unsplit(lapply(split(dat$dt,dat$id),function(x)
x-x[1]),f=dat$id)
dat
# The above code does the trick, but from the standpoint of simplicity, the
ave function seems to be perfect for this problem:
ave(dat$dt,dat$id,FUN=...
2009 Jun 23
3
subset POSIXct
Hi,
I have a data frame with two columns: dt and tf. The dt column is
datetime and the tf column is a temperature.
dt tf
1 2009-06-20 00:53:00 73
2 2009-06-20 01:08:00 73
3 2009-06-20 01:44:00 72
4 2009-06-20 01:53:00 71
5 2009-06-20 02:07:00 72
...
I need a subset of the rows where the minutes are 53. T...
2010 Jun 13
1
ERROR need finite 'ylim' values
Hello:
I use R with MAC
I have a simple data table, numeric and text columns, named dt. The table is
imported through read.csv from a csv file. Row numbers are automatically
assigned, header is set to TRUE. there are 599 rows and several columns.
I am trying to plot using the stripchart command: one numeric variable (say
dt$fnatg) vs a text column (say dt$pat). dt$pat contains one o...
2011 Mar 04
2
questions about using loop, while and next
...and next
In my loop, I have some random generation of data, but if the data doesn't
meet some condition, then I want it to go next, and generate data again for
next round.
# just an example..
# i want to generate the data again, if the sum is smaller than 25
temp=rep(NA, 10)
for(i in 1:10)
{
dt=sum(rbinom(10, 5, 0.5))
while (dt<25) next
temp[i]=dt
}
I also tried while(dt<25) {i=i+1}
But it doesn't seem right to me, since it running nonstop. Any solutions ?
Thanks for helps!
Carrie--
[[alternative HTML version deleted]]
2010 Dec 31
3
survexp - example produces error
..."Error in floor(temp) : Non-numeric argument to mathematical function"
best regards,
Heinz
library(survival)
## Example from help page of survdiff
## Expected survival for heart transplant patients based on
## US mortality tables
expect <-
survexp(futime ~ ratetable(age=(accept.dt - birth.dt),
sex=1,year=accept.dt,race="white"),
jasa, cohort=FALSE,
ratetable=survexp.usr)
Error in floor(temp) : Non-numeric argument to mathematical function
sessionInfo('survival')
R version 2.12.1 Patched (2010-12-18 r538...
2015 Mar 12
2
como hacer una operacion con data.table
Par evitar el warning....
> DT=data.table(col1=1:10)
> DT[,col2:=diff(log(c(1,col1)))]
> DT
col1 col2
1: 1 0.0000000
2: 2 0.6931472
3: 3 0.4054651
4: 4 0.2876821
5: 5 0.2231436
6: 6 0.1823216
7: 7 0.1541507
8: 8 0.1335314
9: 9 0.1177830
10: 10 0.1053605
>
----- Mensaje o...
2010 Aug 04
2
ggplot2 barplot: extra markers in graph
...in the graph that should not be there. This behaviour is not seen when calling the same functions without the position="dodge".
Can someone shed some light on this? How can I avoid this?
#self-contained example:
library(ggplot2)
D<-runif(30)
N<-rep(c(1:10),3)
C<-rep(c(1:3),10)
DT<-data.frame(D=D,N=N,C=C)
#works ok
qplot(DT$N,DT$D,fill=factor(DT$C))+ geom_bar(stat = "identity")
#in the resulting plot, a number of black markers are added that should not be there
qplot(DT$N,DT$D,fill=factor(DT$C))+ geom_bar(stat = "identity", position="dodge"...
2006 May 18
1
Noncentral dt() with tiny 'x' values (PR#8874)
Full_Name: Mike Meredith
Version: 2.3.0
OS: WinXP SP2
Submission from: (NULL) (210.195.228.29)
Using dt() with a non-centrality parameter and near-zero values for 'x' results
in erratic output. Try this:
tst <- c(1e-12, 1e-13, 1e-14, 1e-15, 1e-16, 1e-17, 0)
dt(tst,16,1)
I get: 0.2381019 0.2385462 0.2296557 0.1851817 0.6288373 3.8163916 (!!)
0.2382217
The 0.238 values are okay, the othe...