Re: [R] Fill NA values in columns with values of another column

2024-08-29 Thread Bert Gunter
Dammit. Forgot all about that. Yes, that is the way to do it: with(dat, ave(Value, Group, FUN = \(x)min(x, na.rm = TRUE))) Thanks for resolving my nonsense. -- Bert On Thu, Aug 29, 2024 at 2:58 PM Jeff Newmiller via R-help < r-help@r-project.org> wrote: > Use the ave function. > > On Augu

Re: [R] Fill NA values in columns with values of another column

2024-08-29 Thread Jeff Newmiller via R-help
Use the ave function. On August 29, 2024 2:29:16 PM PDT, Bert Gunter wrote: >Petr et.al: > >I think using merge is a very nice idea! (note that the email omitted the >last rows of the result, though your code of course produced them) > >The only minor problem is that the order of the rows in the

Re: [R] Fill NA values in columns with values of another column

2024-08-29 Thread Bert Gunter
Petr et.al: I think using merge is a very nice idea! (note that the email omitted the last rows of the result, though your code of course produced them) The only minor problem is that the order of the rows in the result is changed from the original. If the OP needs to preserve the original orderi

Re: [R] Fill NA values in columns with values of another column

2024-08-28 Thread Petr Pikal
Hallo Francesca If you had an object with correct setting, something like template > dput(res) structure(list(V1 = c("1", "2", "3", "4", "5", "6", "7", "8"), V2 = c(2, 7, 10, 4, 9, 5, 2, 6)), class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8")) you could merge it with

Re: [R] Fill NA values in columns with values of another column

2024-08-28 Thread Rui Barradas
-Original Message- From: R-help On Behalf Of Rui Barradas Sent: Wednesday, August 28, 2024 4:19 AM To: Francesca PANCOTTO ; r-help@r-project.org Subject: Re: [R] Fill NA values in columns with values of another column [External Email] Às 11:23 de 27/08/2024, Francesca PANCOTTO via R-help escreveu

Re: [R] Fill NA values in columns with values of another column

2024-08-28 Thread Ebert,Timothy Aaron
Sent: Wednesday, August 28, 2024 4:19 AM To: Francesca PANCOTTO ; r-help@r-project.org Subject: Re: [R] Fill NA values in columns with values of another column [External Email] Às 11:23 de 27/08/2024, Francesca PANCOTTO via R-help escreveu: > Dear Contributors, > I have a problem with a da

Re: [R] Fill NA values in columns with values of another column

2024-08-28 Thread Rui Barradas
Às 11:23 de 27/08/2024, Francesca PANCOTTO via R-help escreveu: Dear Contributors, I have a problem with a database composed of many individuals for many periods, for which I need to perform a manipulation of data as follows. Here I report the procedure I need to do for the first 32 observations

Re: [R] Fill NA values in columns with values of another column

2024-08-27 Thread Bert Gunter
Thanks, Calum. After rereading the post, I came to your interpret it as you did. So glad that we agree. "easier" of course is in the mind of the beholder. But I'm glad that you presented a "tidyverse" approach. There are other issues of dependencies and efficiency that also might be relevant. Any

Re: [R] Fill NA values in columns with values of another column

2024-08-27 Thread CALUM POLWART
Bert I thought she meant she wanted to replace the NAs with the 6. But I could be wrong. It looks like the data is combined from cbind. I'm going to give tidyverse examples because it's (/s) *"always"* (/s) easier. require(tidyverse) # impute the missing NAs myData <- cbind(VB1d[,1],s1id[,1])

Re: [R] Fill NA values in columns with values of another column

2024-08-27 Thread Bert Gunter
Sorry, not clear to me. For group 8 in your example, do you want extract the values in column 1 that are not NA, i.e. one value, 6; or do you want to extract the number of values -- that is, the count -- that are not NA, i.e. 1? ... and for group 5, would it be c(9,9) for the values; or 2 for th