similar to: Replace values in a vector

Displaying 20 results from an estimated 700 matches similar to: "Replace values in a vector"

2010 Oct 06
1
replaces a matrix of "NA"s in an array with the previous matrix with numbers
Dear list, Does anyone know if there is a function that replaces a matrix of "NA"s in an array with the previous matrix with numbers? For example, I have an array ab <- array(dim=c(3,3,15),dimnames=list(rows=1:3,cols=1:3,dim=times)) . Select out put from the array is: , , dim = 0.478356969557745 cols rows 1 2 3 1 0.4921053 0 0.5078947 2 0.0000000 0
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
2008 Dec 15
5
how to create duplicated ID in multi-records per subject dataset
Hi R helpers, If I have a dataset looks like: ID record 1 20 . 30 . 25 2 26 . 15 3 21 4..................... And I want it becomes ID record 1 20 1 30 1 25 2 26 2 15 3 21 4..................... That is, I have to duplicate IDs for those with multiple records. I am wondering it is possible to be
2014 Jul 14
2
cummax / cummin for complex numbers
Dear all, in R 3.1.0, this is happening: > cummin(c(1+1i,2-3i,4+5i)) Error in cummin(c(1 + (0+1i), 2 - (0+3i), 4 + (0+5i))) : 'cummax' not defined for complex numbers > cummax(c(1+1i,2-3i,4+5i)) Error in cummax(c(1 + (0+1i), 2 - (0+3i), 4 + (0+5i))) : 'cummin' not defined for complex numbers It may be fixed in R-devel, but I thought I'd mention it to make sure
2015 May 17
1
The function cummax() seems to have a bug.
Hi, The function cummax() seems to have a bug. > x <- c(NA, 0) > storage.mode(x) <- "integer" > cummax(x) [1] NA 0 The correct result of this case should be NA NA. The mistake in [ https://github.com/wch/r-source/blob/trunk/src/main/cum.c#L130-L136] may be the reason. Best Regards, Dongcan -- Dongcan Jiang Team of Search Engine & Web Mining School of Electronic
2008 Jan 07
3
Seeking a more efficient way to find partition maxima
Hi. Suppose I have a vector that I partition into disjoint, contiguous subvectors. For example, let v = c(1,4,2,6,7,5), partition it into three subvectors, v1 = v[1:3], v2 = v[4], v3 = v[5:6]. I want to find the maximum element of each subvector. In this example, max(v1) is 4, max(v2) is 6, max(v3) is 7. If I knew that the successive subvector maxima would never decrease, as in the example,
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 with the method of
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
2009 Dec 30
1
Removing replicated rows
Dear All, I have a matrix like X and need to create a new matrix based on the vector m which gives the number of replicates for each unique row. The resulting matrix should look like y. > x x1 x2 [1,] 2 0.5 [2,] 2 0.5 [3,] 2 0.5 [4,] 6 1.0 [5,] 6 1.0 [6,] 6 1.0 [7,] 1 1.5 [8,] 1 1.5 [9,] 1 1.5 [10,] 4 2.0 [11,] 4 2.0 [12,] 3 2.5 [13,] 3 2.5 [14,] 3 2.5 m<-c(1,1,3,1,2) > y y1 y2
2010 Feb 22
2
Creating regularly spaced time series from irregular one
Hello, I have a series of intraday (high-frequency) 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
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,
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 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
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?
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