Re: [R] Replace NAs in split lists

2018-01-08 Thread PIKAL Petr
> From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] > Sent: Monday, January 8, 2018 4:45 PM > To: Eric Berger > Cc: PIKAL Petr ; r-help@r-project.org; Ek Esawi > > Subject: Re: [R] Replace NAs in split lists > > "Enforce" is overstating it... results will differ

Re: [R] Replace NAs in split lists

2018-01-08 Thread Ek Esawi
Thank you all. Now everything works. Happy 2018 and beyond EK On Sun, Jan 7, 2018 at 10:13 PM, Ek Esawi wrote: > Hi all-- > > I stumbled on this problem online. I did not like the solution given > there which was a long UDF. I thought why cannot split and l/s apply > work here. My aim is to split

Re: [R] Replace NAs in split lists

2018-01-08 Thread ruipbarradas
] 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

Re: [R] Replace NAs in split lists

2018-01-08 Thread William Dunlap via R-help
I don't get exactly that error message, > ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z}) Error: unexpected symbol in "ifelse(is.na(z$Value),z$Value[!is.na (z$Value)][1],z$Value)z" The 'symbol' in "unexpected symbol" refers to a "name" ('z' in this case). The problem is usually at

Re: [R] Replace NAs in split lists

2018-01-08 Thread Ek Esawi
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 wrote: > I don't know. You seem to be posting in HTML so your code is mangled

Re: [R] Replace NAs in split lists

2018-01-08 Thread Jeff Newmiller
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 wrote: >Thank you Jeff.

Re: [R] Replace NAs in split lists

2018-01-08 Thread Ek Esawi
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 O

Re: [R] Replace NAs in split lists

2018-01-08 Thread Jeff Newmiller
>> >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-boun...@r-project.org] On Behalf

Re: [R] Replace NAs in split lists

2018-01-08 Thread Eric Berger
gt; From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff > >> Newmiller > >> Sent: Monday, January 8, 2018 9:13 AM > >> To: r-help@r-project.org; Ek Esawi > >> Subject: Re: [R] Replace NAs in split lists > >> > >> Upon closer examin

Re: [R] Replace NAs in split lists

2018-01-08 Thread Jeff Newmiller
om: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff >> Newmiller >> Sent: Monday, January 8, 2018 9:13 AM >> To: r-help@r-project.org; Ek Esawi >> Subject: Re: [R] Replace NAs in split lists >> >> Upon closer examination I see that you are not using

Re: [R] Replace NAs in split lists

2018-01-08 Thread PIKAL Petr
lp [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff > Newmiller > Sent: Monday, January 8, 2018 9:13 AM > To: r-help@r-project.org; Ek Esawi > Subject: Re: [R] Replace NAs in split lists > > Upon closer examination I see that you are not using the split version of > df1

Re: [R] Replace NAs in split lists

2018-01-08 Thread Jeff Newmiller
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 FALSENA 3 a ac FALSENA 4 b aa TRUE 5 5 b ab FALSE

Re: [R] Replace NAs in split lists

2018-01-07 Thread Jeff Newmiller
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 bre

Re: [R] Replace NAs in split lists

2018-01-07 Thread PIKAL Petr
wi > Sent: Monday, January 8, 2018 4:36 AM > To: r-help@r-project.org > Subject: Re: [R] 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]<- >

Re: [R] Replace NAs in split lists

2018-01-07 Thread Ek Esawi
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 wrote: > Hi all-- > > I stumbled on this prob