search for: locf

Displaying 20 results from an estimated 108 matches for "locf".

Did you mean: loc
2012 Jul 02
2
using "na.locf" from package zoo to fill NA gaps
Hi everybody, I have a small question about the function "na.locf" from the package "zoo". I saw in the help that this function is able to fill NA gaps with the last value before the NA gap (or with the next value). But it is possible to fill my NA gaps according to the last AND the next value at the same time? Actually, I want R to fill my gaps wi...
2003 Nov 14
4
LOCF - Last Observation Carried Forward
Hi! Is there a possibilty in R to carry out LOCF (Last Observation Carried Forward) analysis or to create a new data frame (array, matrix) with LOCF? Or some helpful functions, packages? Karl --------------------------------- Gesendet von http://mail.yahoo.de Schneller als Mail - der neue Yahoo! Messenger. [[alternative HTML version deleted...
2005 May 17
2
cumsum on chron objects
Hi, Is there some alternative to cumsum for chron objects? I have data frames that contain some chron objects that look like this: DateTime 13/10/03 12:30:35 NA NA NA 15/10/03 16:30:05 NA NA ... and I've been trying to replace the NA's so that a date/time sequence is created starting with the preceding available value. Because the number of rows with NA's following each available
2010 Feb 22
2
Creating regularly spaced time series from irregular one
...price data in the form of POSIX timestamp followed by the value. I sucesfuly loaded that into "its" package object. I would like to create from it a regularly spaced time series of prices (for example 1min, 5min, etc apart) so i could calcualte returns. There is an interpolation function locf() that for timestamp with value NA uses last known observation. I guess the idea would be to start from the begining of my series and, for example, if there is no timestamp for t+5min add that time with value NA. Than I could use locf() function to fill those NAs. Finaly I should extract from that...
2011 Sep 30
1
last observation carried forward +1
Hi R-helpers I'm looking for a vectorised function which does missing value replacement as in last observation carried forward in the zoo package but instead of a locf, I would like the locf function to add +1 to each time a missing value occurred. See below for an example. > require(zoo) > x <- 5:15 > x[4:7] <- NA > coredata(na.locf(zoo(x))) [1] 5 6 7 7 7 7 7 12 13 14 15 But what I need is 5 6 7 7+1 7+1+1 7+1+1+1 7+1+1+1+1 12 13...
2010 Jun 28
1
Zoo series to a date time stamp that is regular
NOTE: I will provide data if necessary, but I didn't want clutter everyones mailbox All: I have a time series with level and temperature data for 11 sites for each of three bases. I will have to do this more than once is what I am saying here. OK, The time series are zoo objects with index values in chron format. The problem is that the date and times should be at even 15 min intervals,
2013 Mar 18
2
data.frame with NA
I have this little data.frame http://dl.dropbox.com/u/102669/nanotna.rdata Two column contains NA, so the best thing to do is use na.locf function (with fromLast = T) But locf function doesn't work because NA in my data.frame are not recognized as real NA. Is there a way to substitute fake NA with real NA? In this case na.locf function should work Thank you
2006 Feb 06
5
lme4: Error in getResponseFormula(form) : "Form" must be a two sided formula
I'm sure I'm being stupid so flame away... R2.2.1 on Windoze (boohoo) latest updates of packages. I'm exploring a dataset (land) with three variables looking at an narrowly unbalanced two group (GROUP) ANCOVA of a randomised controlled trial analysing endpoint score (SFQ.LOCF.ENDPOINT) entering the baseline score (SFQ.BASELINE) as covariate and the following work fine: > res.same <- lm(SFQ.LOCF.ENDPOINT ~ SFQ.BASELINE + GROUP,land) > res.diff <- lm(SFQ.LOCF.ENDPOINT ~ SFQ.BASELINE + GROUP + SFQ.BASELINE*GROUP,land) > anova(res.same,res.diff) I try: &gt...
2007 May 10
3
Quick question on merging two time-series of different frequencies
Hi, A quick beginner's question. I have two time series, A with daily data, and another B with data at varying frequencies, but mostly annual. Both the series are sorted ascending. I need to merge these two series together in the following way: For any entry of A, the lookup should match with B until we find an entry of B that's larger than A's. For all A[i], i = 1,...,N and B[j],
2010 Apr 05
2
find the "next non-NA" value within each row of a data-frame
#I wish to find the "next non-NA" value within each row of a data-frame. #e.g. I have a data frame mydata. Rows 1, 2 & 3 have soem NA values. mydata <- data.frame(matrix(seq(20*6), 20, 6)) mydata[1,3:5] <-  NA mydata[2,2:3] <-  NA mydata[2,5] <-  NA mydata[3,6] <-  NA mydata[1:3,] #this loop accomplishes the task; I am tryign toi learn a "better" way for(i
2005 Jun 17
1
aggregate?
Dear all: Here is my problem: Example data: dat<-data.frame(x=rep(c("a","b","c","d"),2),y=c(10:17)) If I wanted to aggregate each level of column dat$x I could use: aggregate(dat$y,list(x=dat$x),sum) But I just want to aggregate two levels (c and d) to obtain a new level e I am expecting something like: x y 1 a 10 2 b 11 3 e 25 4 a 14 5 b 15 6
2008 Dec 16
1
refer to next line within a data-frame an select cases
Hi, I have a problem sorting and selecting entries within a data-frame and I don't know if it is possible to solve it with R ... (probably yes, but I have no idea how). Following Data; row1 row2 a 12 pos NA a 3 neg NA a 5 neg NA a 11 pos NA I want to extract the values in row 2 in the lines with an "a" in row1. But I want to have two vectors: vector x with all
2009 Oct 10
2
Matching Dates Closest without going over
Hi, I have 2 date vectors d1 and d2. d1 <- structure(c(14526, 14495, 14464, 14433, 14402, 14371, 14340, 14309, 14278, 14247, 14216, 14185), class = "Date") d2 <- structure(c(14526, 14509, 14488, 14466, 14453, 14441, 14396, 14388, 14343, 14333, 14310, 14281), class = "Date") I would like to create another dataframe with columns d1 and d2, where d1 is the original d1
2009 Dec 03
4
Replace values in a vector
Hi all, I have a vector like this: x<- c(0.7, 0.1, 0, 0.2, 0.2, 0, 0, 0 , 0, 0.4, 0, 0.8, 1.8) I would like to replace the zero values with the first previous non zero value. my returning vector should look like this: y<-c( 0.7, 0.1, 0.1,0.2,0.2,0.2,0.2,0.2, 0.4, 0.4, 0.8, 1.8) How can I do this in R without using for loop? Thank you
2009 Jun 18
3
Replace zeroes in vector with nearest non-zero value
Folks, If I have a vector such as the following: x <- c(0, -1, -1, -1, 0, 0, 1, -1, 1, 0) and I want to replace the zeroes by the nearest non-zero number to the left, is there a more elegant way to do this than the following loop? y <- x for (i in 2 : length(x)) { if (y[i] == 0) { y[i] <- y[i - 1] } } > y [1] 0 -1 -1 -1 -1 -1 1 -1 1 1 You can see the
2013 Apr 29
1
how to add new rows in a dataframe?
...??????????????? 0??????????????????????? 1.6 3???????????????? 1???????????????????????? 1.2 3???????????????? 4???????????????????????? 1.5 ",sep="",header=TRUE) library(zoo) res1<-do.call(rbind,lapply(split(dat1,dat1$id),function(x) {t1<-seq(min(x$t),max(x$t));scores1<-na.locf(x$scores[match(t1,x$t)]);data.frame(id=rep(unique(x$id),length(t1)),t1,scores1)})) ?row.names(res1)<- 1:nrow(res1) ?res1 #?? id t1 scores1 #1?? 2? 0???? 1.2 #2?? 2? 1???? 1.2 #3?? 2? 2???? 2.3 #4?? 2? 3???? 3.6 #5?? 2? 4???? 5.6 #6?? 2? 5???? 5.6 #7?? 2? 6???? 7.8 #8?? 3? 0???? 1.6 #9?? 3? 1???...
2005 Jun 07
3
without a loop
tmp <- c(-1,NA,NA,1,1,NA,NA,1) without using a loop, how can I replace all NAs in the list above with the previous none NA value in the list?
2011 Jun 15
0
specifying interactions in a gam model with "by"
...ot;N", "S", "S", "N", "S", "S", "N", "N", "N", "N", "N", "N", "S", "N", "S", "S", "N", "S", "S") locf <- as.factor(loc) locN <- as.numeric(loc=="N") locS <- as.numeric(loc=="S") # fit the model with a separate smooth for loc = N and loc = S fit1 <- gam(y ~ locf + s(x, by=locN) + s(x, by=locS)) # fit the model with a separate smooth for each level of the factor loc...
2010 Aug 25
2
Repeat the first day data through all the day. Zoo
down vote favorite Hello I have a zoo series. It lasts 10 years and its frequency is 15min. I'd like to get a new zoo series (or vector) with the same number of elements, whith each element equal to the first element of the day. That's, The first element everyday is repeated throughout the wole day. This is not same as aggregate(originalseries,as.Date,head,1) because this gives a
2011 May 28
1
How to do operations on zoo/xts objects with Monthly and Daily periodicities
Is there an elegant way to do operations (+/-/*/ / ) on zoo/xts objects when one serie is monthly (end of month) and the other daily (weekdays only) - typically a monthly economic indicator and a stock index price? Thanks, TDB -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-operations-on-zoo-xts-objects-with-Monthly-and-Daily-periodicities-tp3558081p3558081.html