Displaying 20 results from an estimated 10000 matches similar to: "if block and brackets"
2004 Mar 27
1
building a list in loop
Hello
getdata <- function(p){
fname <- NULL; dl <- list()#build the sturcture
builddl <- function(q,s){
fname <<- c(fname,s) #where "s" is a string
dl <<- list( dl, dt2)
}
list(names = fname, data = dl)
}
data <- getdata("c:\somepath")
> data
$names
[1] "fname"
$data
$data[[1]] <--- since there is no [[1]] how can I
stop
2016 Feb 26
0
Is a PHI use of another PHI in the same block valid?
If we decide not to be legal, should we change the verify to reject
it? What happens to the test cases that currently test this very
situation (eg. Transforms/LoopVectorize/phi-hang.ll)?
The change as suggested by Philip is:
- Assert(InstsInThisBlock.count(Op) || DT.dominates(Op, U),
+ Assert((!isa<PHINode>(I) && InstsInThisBlock.count(Op)) ||
+ DT.dominates(Op, U),
+
2008 Jul 28
2
Help with a loop
HI:
I need ideas on how to make this code shorter (maybe with a second loop?).
The code as it is works, but in this case I only have 14 samples, but it
will become insane with more, so I need a way to make it more automatic. 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
2017 Nov 03
0
repeat a function
Hi
Well, I am not an expert in this field so I cannot comment your approach. I wanted only to point out that building matrix your way is like scratching your left ear with right hand, especially in R. What 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
2017 Nov 02
2
repeat a function
Hi Petr,
Many thanks for your response.
Basically I want to create a probability matrix to be used in a trinomial tree going forward. This is the reason why I thought to build the matrix around 0 would be much more efficient. I need to loop through because the probabilities will depend on my node and is not always the same per row (e.g. if N> jmax, jmax being defined in another function)
I
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
0
repeat a function
Hi Eric
I did not see any answer and frankly speaking I cannot provide you with canned help.
AFAIK if a function is defined within another function (which is your case) it cannot be called directly so it is necessary to define it in global environment.
> fff <- function(x) {
+ myf <- function(a) a+2
+ myf(x)^2}
>
> fff(5)
[1] 49
> myf(5)
Error in myf(5) : could not find
2017 Jul 22
1
3-day moving average for block maxima
Dear r-users,
I would like to construct 3-day moving average for block maxima series.
I tried this:
bmthree <- lapply(split(dt, dt$Year), function(x) max(sapply(1:(nrow(x)-2),
function(i) with(x, mean(Amount[i:(i+2)],na.rm=TRUE)))))
bmthree
and got the following output.
$`1971`
[1] 70.81667
$`1972`
[1] 68.94553
$`1973`
[1] 102.7236
$`1974`
[1] 73.6625
$`1975`
[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)) {
for (j in nrow(A.DT):1) {
if
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])
2010 Sep 24
1
color of lines while printing through for loop
I am trying to find a convenient way to control line colors when
printing from a for loop using the lines command.
Right now I have solved this by creating a colors vector that is refered
to in the loop with index. However, the colors choosen here are just
1,2,3,4,5...
I would like to get colors from the col = rainbow(x) that you can use in
plot() and set the to be my number of lines (I think
2006 Nov 20
2
problem with loop to put data into array with missing data for some files
Dear R-help community,
My main goal of this message is to find a way of skipping a file of a month/year
in a loop that does not exist (and making it's output into an data.out array
would be NA) and moving onto the next year/month in the loop to carry on filling
data.out with real precipitation data.
The situation so far:
I downloaded 50 years worth of GRIB data files from the NCEP data
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 of 3 values:
2012 Dec 03
1
Confidence bands with function survplot
Dear all,
I am trying to plot KM curves with confidence bands with function survplot under package rms.
However, the following codes do not seem to work. The KM curves are produced, but the confidence bands are not there.
Any insights? Thanks in advance.
library(rms)
########data generation############
n <- 1000
set.seed(731)
age <- 50 + 12*rnorm(n)
label(age) <- "Age"
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
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 original -----
De: "Carlos Ortega" <cof en
2010 Aug 04
2
ggplot2 barplot: extra markers in graph
Dear List,
(self-contained example + version info at the bottom)
I'm having trouble producing a barplot using the functions in ggplot2. When I use the position="dodge" option, the bars are plotted but also a number of spurious markers. More specifically, a number of black dots are plotted in the graph that should not be there. This behaviour is not seen when calling the same
2006 Jun 29
1
Question on memory allocation & loop
Hello All,
I am trying to work on writing the following piece of (pseudo)
code in an optimal fashion:
----------------------------------------------------
# Two data frames with some data
a = data.frame(somedata)
b = data.frame(somedata)
for(i in 1:nrow(dt) {
# Merge dates for a given date into a new data frame
c = merge(a[a$dt==dt[i],),b[b$dt == dt[i],], by=c(some column));
}
2006 Nov 20
3
problem with loop to put data into array with missing data forsome files
Hi Jenny
If you want a general solution I understand.
However I just downloaded the file fine (as far as I can tell) so you
are welcome to have a copy. I can email it to you if you want.
I do not think your test for NA is valid. i.e
if(test != "NA"){
}
I think you should use
if(is.na(test)){
}
Or something similar.
J
---
John Seers
Institute of Food Research
Norwich
2008 Mar 04
1
help needed on function call
Hi there,
I am confused about fucntion call. After defining a function, I called it
within another function.
dt<-cars; #a copy of R internal dataset "cars" created;
dt$cat1<-ifelse(dt$speed<20,0,1);
dt$ind<-ifelse(dt$speed<15,1,2); #group variable;
freqtot <- function(data,var){
attach(data,warn.conflicts=FALSE)
x1 <- data.frame(table(var))