similar to: help with for loop

Displaying 20 results from an estimated 20000 matches similar to: "help with for loop"

2008 Mar 02
1
question on lag.zoo
Hi Guys, I'm using zoo package now. I found lag is not doing what I assumed. > x <- zoo(11:21) > z <- zoo(1:10, yearqtr(seq(1959.25, 1961.5, by = 0.25)), frequency = 4) > x 1 2 3 4 5 6 7 8 9 10 11 11 12 13 14 15 16 17 18 19 20 21 > lag(x) 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 > z 1959 Q2 1959 Q3 1959 Q4 1960 Q1 1960 Q2 1960 Q3 1960 Q4
2009 Oct 12
1
Using diff, ifelse on zoo object
Hi, I'm having an issue when using diff and ifelse on a zoo object..... x.Date <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1 x <- zoo(rnorm(5), x.Date) x.POS <- c(0,0,0,1,1) x<- merge(x,x.POS) x x x.POS 2003-02-01 -0.1858136 0 2003-02-03 -1.3188533 0 2003-02-07 0.2709794 0 2003-02-09 -1.4915262 1 2003-02-14
2004 Nov 28
3
Correct Syntax for a Loop
I'll appreciate if some one can help me with the following loop. This is the logic of the loop, if we have the following data; > x.df x.dif . . . . 102 0.00 103 0.42 104 0.08 105 0.00 106 0.00 107 0.00 108 -0.16 109 -0.34 110 0.00 111 -0.17 112 -0.33 113 0.00 114 0.00 115 0.00 116 0.33 117 0.17 118 0.00 . . . . I'm trying to find i's where for (i
2004 Nov 04
5
Conversion of strings to expressions
Hello, I'm not sure how to state my question in a technically accurate manner, so I'll use a short example to clarify my problem: Say I have a vector, vec<-c(1,2,3,2) I would like to be able to "reference" the vector by using the string containing the name of the vector - that is, I would like to know of some function which is able to convert the string "vec"
2009 Aug 19
2
line plot
Dear useRs, How can I draw a barplot, but instead of bars, I'd get lines? Thanks, Kind regards, Rafael. ____________________________________________________________________________________ [[elided Yahoo spam]] [[alternative HTML version deleted]]
2009 Sep 08
4
barplot with lines instead of bars
Dear useRs, I want to plot the following barplot with lines instead of bars. Is there a way? data <- data.frame(cbind(k = 0:3, fk = c(11, 20,7,2), f0k = c(13.72, 17.64, 7.56, 1.08), fkest = c(11.85, 17.78, 8.89, 1.48))) d <- t(data[,2:4]) barplot(d, beside=TRUE) Regards, Rafael. ____________________________________________________________________________________ [[elided Yahoo
2012 Nov 01
2
Subsetting year range
Hi, I have a panel data set that I am trying to subset. I am trying to keep values for years >=1960. The full set is from 1940 to 2000. I tried a few things, but none worked. Here are a couple that I am trying to use. TableAPS1 <- subset(TableAP, year => 1959) TableAPS1 <- TableAP[ which(year > 1959),] It would be really nice if someone can point out what I am doing wrong
2010 Jul 31
1
Lags and Differences of zoo Objects
Hi, I'm struggling to understand the documentation. ?lag.zoo x - a "zoo" object. k, lag - the number of lags (in units of observations). Note the sign of k behaves as in lag. differences - an integer indicating the order of the difference. What does the above line actually mean? I've tried a few settings on sample data but can't figure out what it is doing. x <-
2009 Mar 21
1
How to avoid switching on input type?
Hi, I need some help improving this ugly code I wrote. I would like to shift forward a zoo object, matrix, ts, or list by "shift" items (default 1) and fill the holes with 0's. The code below works, but it looks ugly. I could write a function lag.zerofill() which calls the two functions below depending on the class() of the item passed in, but that feels very unlike R. What is
2011 Aug 25
1
Autocorrelation using acf
Dear R list As suggested by Prof Brian Ripley, I have tried to read acf literature. The main problem is I am not the statistician and hence have some problem in understanding the concepts immediately. I came across one literature (http://www.stat.nus.edu.sg/~staxyc/REG32.pdf) on auto-correlation giving the methodology. As per that literature, the auto-correlation is arrived at as per following.
2008 Jan 31
1
Feature request: about lag(), which.min() and cat().
Hello I'm only user of R and have many little knowledge in programming but I permit to send you some whishes/suggestions for R. which.min like which(), which.min() should also include an argument arr.ind. Note that one can have it with which(a==min(a), arr.ind=TRUE) but if there is a reason to build a special function which.min, why not add also this nice argument? lag() If one wants to
2008 Jun 03
1
using function from specific packages
hello, useRs- i have a function that i wrote myself, for example, lag(x). however, when i load 'zoo' packages and try to lag 'zoo' object, it gave me error. (R try to pass 'zoo' object into my function.) i typed 'lag.zoo' in R, but it can't find it. how can i access 'lag.zoo' function? and in general, how can i deal with such problem as to access
2009 Feb 11
2
Question about apply()
Hello, everyone! Assume you have this data: data <- structure(c(66.609375, 67.09375, 66.40625, 66.734375, 67.109375, 66.875, 66.09375, 65.921875, 66.546875, 66.140625, 66.140625, 65.65625, 65.875, 65.59375, 65.515625, 66.09375, 66.015625, 66.140625, 66.109375, 66.421875, 1702.7, 1647.7, 1649.4, 1639.9, 1696.4, 1710.9, 1690.2, 1677.9, 1694.4, 1713.9, 1713.9, 1705.4, 1708.4, 1692.9, 1689.6,
2009 Oct 22
1
Error in link in Rd file stops package installation
With a pretty recent version of R 2.11.0 (devel,unstable, svn 50178) on Linux I could not install version 1.5-8 of zoo (the current on on CRAN): % R-devel CMD INSTALL -l Rlib3 zoo * installing *source* package 'zoo' ... ** R ** inst ** preparing package for lazy loading ** help *** installing help indices converting help for package 'zoo' finding
2009 Jan 04
1
POSIXct and chron issues with tz
Dear All- I am trying to merge two data files - they have different date formats and different times zones. I need to match up the date/time of the datasets and then invoke a conditional statement, such as: if dataC$mph is >= 12 then keep dataM$co23 for the corresponding time/date stamp. snippets of data files: *dataC.txt* LST in mph Deg DegF DegF2 % volts Deg
2009 Mar 21
4
Problem with zoo and rbind() converting matrix to vector
require( zoo ) inp <- c( 5, 9, 4, 2, 1 ); m <- zoo( cbind( inp ), as.Date("2003-02-01") + (0:(length(inp)-1))); dim( m ) # [1] 5 1 dim( m[1,,drop=FALSE] ) # [1] 1 1 - ok dim( lag( m, -1 )) # [1] 4 1 - ok dim( rbind( m[1,,drop=FALSE], lag(m,-1) )) # NULL - converted from zoo matrix to zoo vector!?!? # any way to keep the last line as a zoo matrix??? -- View this message in
2009 Aug 20
3
categorized barplot
Dear useRs, I can't seem to find out how to categorize my histogram. I have the following dataset: Time??????????? First.day? Second.day 08:00-10:00??????? 9?????????? ? 8 10:00-12:00?????? 13???????? ? 15 12:00-14:00??????? 9?????????? ? 9 14:00-16:00???????10????????? ? 9 I attached a jpeg file to this e-mail containing the sketches. What I'd like to do is a barplot (or histogram),
2012 Jun 06
2
package zoo, function na.spline with option maxgap -> Error: attempt to apply non-function?
Hello, I'm trying to use na.spline (package zoo) to fill some missing data in a time series. this works fine, however, if I apply the 'maxgap' argument, I always get the error: <------ Error in na.spline.vec(x., coredata(object.), xout = xout., ...) : attempt to apply non-function ------> I couldn't find a similar error for this case in the mailing lists and zoo vignette,
2007 Jul 12
2
lead
Hi, is there any function in R that shifts elements of a vector to the opposite direction of what Lag() of the Hmisc package does? (something like, Lag(x, shift = -1) ) Thanks Zava -------------------------------------------------------- This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
2009 Jul 24
1
Lag representation in ccf() while zoo object is used?
Dear All, I have 2 time-series data sets and would like to check the cross correlation. These data sets were set as a zoo object, called data, and in general look like: V1 V2 2007-01-01 00:00:00 0.0 0.176083 2007-01-01 01:00:00 0.0 0.176417 2007-01-01 02:00:00 0.0 0.175833 2007-01-01 03:00:00 0.0 0.175833 2007-01-01