similar to: Replace NAs in split lists

Displaying 20 results from an estimated 3000 matches similar to: "Replace NAs in split lists"

2018 Jan 08
2
Replace NAs in split lists
Thank you Jeff. Your code works, as usual , perfectly. I am just wondering why if i put the whole code in one line, i get an error message. sdf2 <- lapply( sdf, function(z){z$Value <-ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z}) error. unexpected symbol in sdf2 Thanks again EK On Mon, Jan 8, 2018 at 3:12 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: >
2018 Jan 08
3
Replace NAs in split lists
Why do you want to modify df1? Why not just reassemble the parts as a new data frame and use that going forward in your calculations? That is generally the preferred approach in R so you can re-do your calculations easily if you find a mistake later. -- Sent from my phone. Please excuse my brevity. On January 7, 2018 7:35:59 PM PST, Ek Esawi <esawiek at gmail.com> wrote: >I just came
2018 Jan 08
0
Replace NAs in split lists
I just came up with a solution right after i posted the question, but i figured there must be a better and shorter one.than my solution sdf1[[1]][1,4]<-lapplyresults[[1]] sdf1[[2]][1,4]<-lapplyresults[[2]] EK On Sun, Jan 7, 2018 at 10:13 PM, Ek Esawi <esawiek at gmail.com> wrote: > Hi all-- > > I stumbled on this problem online. I did not like the solution given > there
2018 Jan 08
0
Replace NAs in split lists
Upon closer examination I see that you are not using the split version of df1 as I usually would, so here is a reproducible example: #---- df1 <- read.table( text= "ID ID_2 Firist Value 1 a aa TRUE 2 2 a ab FALSE NA 3 a ac FALSE NA 4 b aa TRUE 5 5 b ab FALSE NA ", header=TRUE, as.is=TRUE ) sdf <- split( df1, df1$ID ) # note the extra [ 1 ]
2018 Jan 08
0
Replace NAs in split lists
I don't know. You seem to be posting in HTML so your code is mangled. Can you post plain text and use the reprex package to make sure it produces the errorin a clean R session? -- Sent from my phone. Please excuse my brevity. On January 8, 2018 8:03:45 AM PST, Ek Esawi <esawiek at gmail.com> wrote: >Thank you Jeff. Your code works, as usual , perfectly. I am just >wondering why
2018 Jan 08
1
Replace NAs in split lists
OPS! Sorry i did indeed posted the code in HTML; should have known better. ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z}) error. unexpected symbol in sdf2 On Mon, Jan 8, 2018 at 11:44 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: > I don't know. You seem to be posting in HTML so your code is mangled. Can you post plain text and use the reprex package to
2018 Jan 08
2
Replace NAs in split lists
Hi With the example, na.locf seems to be the easiest way. > library(zoo) > na.locf(df1) ID ID_2 Firist Value 1 a aa TRUE 2 2 a ab FALSE 2 3 a ac FALSE 2 4 b aa TRUE 5 5 b ab FALSE 5 Cheers Petr > -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Jeff > Newmiller > Sent: Monday, January
2018 Jan 08
2
Replace NAs in split lists
You can enforce these assumptions by sorting on multiple columns, which leads to na.locf(df1[ order(df1$ID,df1$Value), ]) On Mon, Jan 8, 2018 at 4:19 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: > Yes, you are right if the IDs are always sequentially-adjacent and the > first non-NA value appears in the first record for each ID. > -- > Sent from my phone. Please
2018 Jan 08
0
Replace NAs in split lists
Yes, you are right if the IDs are always sequentially-adjacent and the first non-NA value appears in the first record for each ID. -- Sent from my phone. Please excuse my brevity. On January 8, 2018 2:29:40 AM PST, PIKAL Petr <petr.pikal at precheza.cz> wrote: >Hi > >With the example, na.locf seems to be the easiest way. >> library(zoo) > >> na.locf(df1) > ID
2018 Jan 08
0
Replace NAs in split lists
"Enforce" is overstating it... results will differ if there are no non-NA values for a given ID, and there is a potential further discrepancy if there are multiple non-NA values. But these issues were not identified by the OP, so may not be relevant in their case. -- Sent from my phone. Please excuse my brevity. On January 8, 2018 6:41:33 AM PST, Eric Berger <ericjberger at
2018 Jan 08
0
Replace NAs in split lists
Because you need to separate the instructions with a ; (semi-colon). Hope this helps Rui Barradas Enviado a partir do meu smartphone Samsung Galaxy.-------- Mensagem original --------De: Ek Esawi <esawiek at gmail.com> Data: 08/01/2018 16:03 (GMT+00:00) Para: Jeff Newmiller <jdnewmil at dcn.davis.ca.us>, r-help at r-project.org Assunto: Re: [R] Replace NAs in split lists Thank you
2017 Aug 09
2
Fill in empty spaces modified
Hi All? I was looking at a posting from June-17. I managed to solve it. However, when I changed the example in the posting, my solution will work only once at a time which was mentioned by Jim Lemon on his response to the original posting. This means that my solution will have to be repeated as many times as the maximum number of spaces on each gap; something that may not work well for large
2017 Nov 22
1
assign NA to rows by test on multiple columns of a data frame
OPS, Sorry i did not read the post carfully. Mine will not work if you have zeros on columns A and B.. But you could modify it to work for specific columns i believe. EK On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi <esawiek at gmail.com> wrote: > Hi *Massimo,* > > *Try this.* > > *a <- mydf==0mydf[a] <- NAHTHEK* > > On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan
2018 Jan 22
2
substr gives empty output
In y <- substr(x, i, 1) your third integer needs to be the location not the number of digits, so change it to y <- substr(x, i, i) and you should get what you want. Cheers, Tim > Date: Sun, 21 Jan 2018 10:50:31 -0500 > From: Ek Esawi <esawiek at gmail.com> > To: Luigi Marongiu <marongiu.luigi at gmail.com>, r-help at r-project.org > Subject: Re: [R] substr
2017 Oct 29
1
Count non-zero values in excluding NA Values
Dear R Staff This is my file (www.fiscalforecasting.com/data.csv) if you don't download this file, my dataset same as following Year Month A B C D E 2005 July 0 *4* NA NA *1* 2005 July 0 NA NA 0 *9* 2005 July NA *4* 0 *1* 0 2005 July *4* 0 *2* *9* NA I try to count non-zero values which are not NA values for every *column* *Sincerely* *Engin YILMAZ*
2017 Jun 21
3
Counting with multiple criteria using data table
I have a data.table which is shown below. I want to count combinations of columns on i and count on j with by. A few examples are given below the table. I want to: all months to show on the output including those that they have zero value I want the three statements combined in on if possible so the output will be one data table; that is the outputs are next to each other as manually
2018 Feb 27
3
Aggregate over multiple and unequal column length data frames
Thank you Pikal and Bert. My apology for posting parts of my previous email in HTML. Bert's suggestion will work but i am wondering if there is an alternative especially in the case where the data frames are big; that is the difference in lengths among them is large. Below is a list of sample date frames and desired result. EK
2018 Feb 21
3
Aggregate over multiple and unequal column length data frames
Hi All-- I have generated several 2 column data frames with variable length. The data frames have the same column names and variable types. I was trying to aggregate over the 2nd column for all the date frames, but could not figure out how. I thought i could make them all of equal length then combine them in 1 data frame where i can use aggregate, the formula version Or to put them in a list and
2017 Oct 29
0
Count non-zero values in excluding NA Values
What was suggested by Eric and Rui works well, but here is a short and may be simpler answer provided your data is similar what Eric posted. It should work for your l data too. aa <- is.na(data)|data==0 nrow(data)-colSums(aa) EK On Sun, Oct 29, 2017 at 6:25 AM, Engin YILMAZ <ispanyolcom at gmail.com> wrote: > Dear R Staff > > You can see my data.csv file in the annex. >
2017 Aug 09
1
Fill in empty spaces modified
Thank you so much Jim. I forgot to state that i was hoping to get it without loops if possible. Thanks again, EK [[alternative HTML version deleted]]