similar to: Fill in NA values in vector with previous character/factor

Displaying 20 results from an estimated 10000 matches similar to: "Fill in NA values in vector with previous character/factor"

2012 Oct 18
1
filling NA gaps according to previous data mean and following data mean
Hi everybody, I have a little problem about filling some gaps of NAs in my data. These gaps are between nearly constant data (temperature under snow). Here's a fake example to illustrate how it looks like approximately: DF <- data.frame(data=c(-0.51,-0.51,-0.48,-0.6,-0.54,-0.38,-0.6,-0.42,NA,NA,NA,NA,NA,NA,NA, -0.25,-0.41,-0.5,-0.5,-0.35,-0.7,-1,-0.87)) I would like to replace my NAs
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]]
2017 Jun 25
1
Fill in empty cell in data.frame from previous value
Excellent Boris, thx ? this helps From: Boris Steipe Sent: June 25, 2017 11:23 AM To: Christophe Elek Cc: r-help at r-project.org Subject: Re: [R] Fill in empty cell in data.frame from previous value Run it through a loop. I assume the cell contents is NA (Not Available). Test for it with is.na(). Whenever that returns TRUE, replace the NA value with the value from the previous row. Cheers, B.
2006 Mar 02
4
Skip last NA's?
I wonder if anyone could help me find an expression for skipping the last missing values in a vector? The kind of material I have is something like x<-c(23,12,NA,23,24,21,NA,NA,NA) I would like to skip the last NA's, but not the ones in between other vallues. Any hints? (Why not do this by simply take x[1:6]? I have several vectors a couple of thousand observations long with varying
2011 May 18
1
matrix help (first occurrence of variable in column)
Dear R help, Apologies for the less than informative subject line. I will do my best to describe my problem. Consider the following matrix: mdat <- matrix(c(1,0,1,1,1,0), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("T1", "T2"), c("sp.1", "sp.2", "sp.3"))) mdat In my actual data I have time
2008 Nov 20
2
how to replace NA with previous numbers
Hi, I have a vector with lots of NAs. e.g. vec = c(NA, NA, 2, NA, NA, 5, NA, 6, NA) > vec [1] NA NA 2 NA NA 5 NA 6 NA I would like to replace NAs with their immediately previous non NA number. After replacement, the above vector will become > vec [1] 0 0 2 2 2 5 5 6 6. I understand how to do that with a loop but the actual vector is very long and the loop takes too much time in R.
2010 May 11
3
Smoothing Techniques - short stepwise functions with spikes
R Friends, I have data from which I would like to learn a more general (smoothened) trend by applying data smoothing methods. Data points follow a positive stepwise function. | x x | xxxxxxxx xxxxxxxx | x x |xxxx xxx xxxx | xxxxxxxxxxxxxxxxx | |
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
2008 Apr 06
3
how to manupute data frame with conditions fill cell with previous value if next cell is zero
Dear R Experts, This is the 2nd time in the chat room. Its a great place to get help from R experts. I have a data frame problem, it contains thousands of data. part of it, I am giving for explaining the problem date day x y z 82 1989-04-28 Fri 2118.0 2418.80 33713 83 1989-05-01 Mon 0.0 2414.96 33793 84 1989-05-02 Tue 2103.1 2402.86 33955
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
2007 Aug 22
3
Help with vector gymnastics
Hello, What is the best way of solving this problem? answer <- ifelse(tf=TRUE, i * 5, previous answer) where as an initial condition tf[1] <- TRUE For example if, tf <- c(T,F,F,F,T,T,F) over i = 1 to 7 then the output of the function will be answer = 5 5 5 5 25 30 30 Thank you. Phil,
2010 Jun 30
1
merge.zoo and fill
Hello again, I merge different zoo time series with prices at different dates. This returns a multivariate zoo object with NA's at various points i.e., 2010-02-28 NA NA NA NA 850.2 2444.4 NA NA NA NA NA NA NA 2010-03-01 61.1 55.3 61.5 81.24 NA NA 1712.2 3.3 11139.3 163.7 2242.4 9015.6 109.791 2010-03-31
2011 Jun 23
3
problem (and solution) to rle on vector with NA values
Hello there R-help, I'm not sure if this should be posted here - so apologies if this is the case. I've found a problem while using rle and am proposing a solution to the issue. Description: I ran into a niggle with rle today when working with vectors with NA values (using R 2.31.0 on Windows 7 x64). It transpires that a run of NA values is not encoded in the same way as a run of other
2010 Apr 09
3
"fill in" values between rollapply
Hi, Sorry ahead of time for not including data with this question. Using rollapply to calculate mean values for 5 day blocks, I'd use this: Roll5mean <- rollapply(data, 5, mean, by=5, align = c("left")) My question is, can someone tell me how to fill in the days between each of these means with the previously calculated mean? If this doesn't make sense, I will clarify and
2012 Nov 22
2
Trick to replace NA
Dear members, I have a series of values in a vector and some value are missing and replaced with NA. For example: a <- c(27, 25, NA, NA, 24, 26, 27, NA, 26) I would like to replace the NAs with the value taken from the previous value that is non-NA. The output would be in this case: 27 25 25 25 24 26 27 27 26 Now I do that with a for loop, but I try to eliminate all the loops to gain in
2012 Nov 29
2
Data Cleaning -New user coming from SAS
Hello, this is my first post. I have a large CSV file where I need to fill in the 1st and 2nd column with a Loan # and Account name that would be found in a line of text : like this: ,,Loan #:,ML-113-07,Account Name:, Quilting Boutique,,,,,,,,,,, I would like to place the Loan #: ML-113-07 in the first column and the account name quilting boutique in the second column. If possible I would also
2007 Jun 30
1
Importing an Excel file that has merged cells
Dear all, I have a problem with importing an excel file into R. I can open the file easily (either saving it as a CSV or using RODBC). But the original file is using merged cell in its first column, which gives the name of the observation. (I am dealing with repeated measurements for the same observation) So when I open the dataframe in R it looks like this Col1 Col2 Col3 name1 val1 val2
2012 Jul 10
3
fill 0-row data.frame with 1 line of NAs
Dear all Is there a simpler method to achieve the following: When I obtain an empty data.frame after subsetting, I need for it to contain one line of NAs. Here's a dummy example: > (.xb <- iris[ iris$Species=='zz', ]) [1] Sepal.Length Sepal.Width Petal.Length Petal.Width Species <0 rows> (or 0-length row.names) > dim(.xb) [1] 0 5 > (.xa <-
2002 Jun 05
5
hairy indexing problem
I've got a data frame that looks like this: subject foo bar 2 1.7 3.2 2 2.3 4.1 3 7.6 2.3 3 7.1 3.3 3 7.3 2.3 3 7.4 1.3 5 6.2 6.1 5 3.4 6.9 ... That is, I've got multiple rows per subject. I need to compute summaries within categories where the subject has the same number