similar to: any and all

Displaying 20 results from an estimated 10000 matches similar to: "any and all"

2024 Apr 13
1
any and all
Hi Avi, As D?nes T?th has rightly diagnosed, you are building an "all or nothing" filter. However, you do not need to explicitly spell out all columns that you want to filter for; the "tidy" way would be to use a helper function like `if_all()` or `if_any()`. Consider this example (I hope I understand your intentions correctly): ``` library(dplyr) data <- tribble(
2024 Apr 12
1
any and all
On 12/04/2024 3:52 p.m., avi.e.gross at gmail.com wrote: > Base R has generic functions called any() and all() that I am having trouble > using. > > It works fine when I play with it in a base R context as in: > >> all(any(TRUE, TRUE), any(TRUE, FALSE)) > [1] TRUE >> all(any(TRUE, TRUE), any(FALSE, FALSE)) > [1] FALSE > > But in a tidyverse/dplyr
2024 Apr 12
1
any and all
Hi Avi, As Duncan already mentioned, a reproducible example would be helpful to assist you better. Having said that, I think you misunderstand how `dplyr::filter` works: it performs row-wise filtering, so the filtering expression shall return a logical vector of the same length as the data.frame, or must be a single boolean value meaning "keep all" (TRUE) or "drop all"
2024 May 25
1
dplyr, group_by and selective action according to each group
Although there may well be many ways to do what is being asked for with the tidyverse, sometimes things are simple enough to do the old-fashioned way. The request seems to have been to do something to all rows in ONE specific group but was phrased in the sense of wanting to know which group your functionality is being called in. What grouping gains you is more worthwhile if you are interested in
2018 Mar 22
1
Calculate weighted proportions for several factors at once
Hi, I have a grouped data set and would like to calculate weighted proportions for a large number of factor variables within each group member. Rather than using dplyr::count() on each of these factors individually, the idea would be to do it for all factors at once. Does anyone know how this would work? Here is a reproducible example: ############################################################
2024 Jul 22
3
Extract
Base R. Regarding code improvements: 1. Personally I find (\(...) ...)() notation hard to read (although by placing (\(x), the body and )() on 3 separate lines it can be improved somewhat). Instead let us use a named function. The name of the function can also serve to self document the code. 2. The use of dat both at the start of the pipeline and then again within a later step of the pipeline
2024 May 24
1
dplyr, group_by and selective action according to each group
Laurent: As I don't use dplyr, this won't help you, but I hope you and others may find it entertaining anyway. If I understand you correctly (and ignore this if I have not), there are a ton of ways to do this in base R, including using switch() along the lines you noted in your post. However, when the functions get sufficiently complicated or numerous, it may be useful to store them in a
2024 Dec 01
2
Identify first row of each ID within a data frame, create a variable first =1 for the first row and first=0 of all other rows
Rui: "f these two, diff is faster. But of all the solutions posted so far, Ben Bolker's is the fastest." But the explicit version of diff is still considerably faster: > D <- c(rep(1,10),rep(2,6),rep(3,2)) > microbenchmark(c(1L,diff(D)), times = 1000L) Unit: microseconds expr min lq mean median uq max neval c(1L, diff(D)) 3.075 3.198 3.34396
2024 Oct 17
2
DPLYR Multiple Mutate Statements On Same DataFrame
Hi R Helpers, I have been looking for an example of how to execute different dplyr mutate statements on the same dataframe in a single step. I show how to do what I want to do by going from df0 to df1 to df2 to df3 by applying a mutate statement to each dataframe in sequence, but I would like to know if there is a way to execute this in a single step; so simply go from df0 to df1 while executing
2024 Jul 22
1
Extract
Thanks. I found this to be quite informative and a nice example of how useful R-Help can be as a resource for R users. Best, Bert On Mon, Jul 22, 2024 at 4:50?AM Gabor Grothendieck <ggrothendieck at gmail.com> wrote: > > Base R. Regarding code improvements: > > 1. Personally I find (\(...) ...)() notation hard to read (although by > placing (\(x), the body and )() on 3
2024 Oct 18
1
DPLYR Multiple Mutate Statements On Same DataFrame
?s 22:50 de 17/10/2024, Sparks, John escreveu: > Hi R Helpers, > > I have been looking for an example of how to execute different dplyr mutate statements on the same dataframe in a single step. I show how to do what I want to do by going from df0 to df1 to df2 to df3 by applying a mutate statement to each dataframe in sequence, but I would like to know if there is a way to execute this
2018 May 30
2
Filtering using multiple rows in dplyr
Hi Folks, I have just started using dplyr and could use some help getting unstuck. It could well be that dplyr is not the package to be using, but let me just pose the question and seek your advice. Here is my basic data frame. head(h) subject ageGrp ear hearingGrp sex freq L2 Ldp Phidp NF SNR 1 HALAF032 A L A F 2 0 -23.54459 55.56005 -43.08282
2017 Nov 29
0
dplyr - add/expand rows
Hi Martin, On 11/29/2017 10:46 PM, Martin Morgan wrote: > On 11/29/2017 04:15 PM, T?th D?nes wrote: >> Hi, >> >> A benchmarking study with an additional (data.table-based) solution. > > I don't think speed is the right benchmark (I do agree that correctness > is!). Well, agree, and sorry for the wording. It was really just an exercise and not a full
2023 Nov 07
1
make a lattice dotplot with symbol size proportional to a variable in the plotted dataframe
Hello. My question is in the subject line. Using R 4.1.3 on Windows 10. Commented MWE below. Thanks. --Chris Ryan library(dplyr) library(lattice) ## fabricate a dataframe dd <- data.frame(agency = sample(LETTERS, size = 5), total = sample(100:200, size = 5), las = sample(20:40, size = 5)) dd <- dd %>% mutate(proportion = las/total, bubble = total/100) ## attempt to make a dotplot
2024 Nov 27
4
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Check out the dplyr package, specifically the mutate function. # Create new column based on existing column value df <- df %>% mutate(FirstDay = if(ID = 2, 5)) df Repeat as needed to capture all of the day/firstday combinations you want to account for. Like everything else in R, there are probably at least a dozen other ways to do this, between base R and all of the library packages
2017 Nov 29
2
dplyr - add/expand rows
On 11/29/2017 04:15 PM, T?th D?nes wrote: > Hi, > > A benchmarking study with an additional (data.table-based) solution. I don't think speed is the right benchmark (I do agree that correctness is!). For the R-help list, maybe something about least specialized R knowledge required would be appropriate? I'd say there were some 'hard' solutions -- Michael (deep
2020 Oct 30
3
Error: variable not found
Hello I have a question. I made an r-script and did a few commands needed to make some new variables. They all work out well, and when I run the commands, the new variables appear in the dataset. I can also work with these new variables to make other new variables from them. Also, when I use summary(dataset), those new variables appear in the summary of the dataset. But, when I do summary(new
2023 Jan 15
2
Removing variables from data frame with a wile card
I am new to this thread. At the risk of presenting something that has been shown before, below I demonstrate how a column in a data frame can be dropped using a wild card, i.e. a column whose name starts with "th" using nothing more than base r functions and base R syntax. While additions to R such as tidyverse can be very helpful, many things that they do can be accomplished simply
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: >
2024 Sep 04
2
Calculation of VCV matrix of estimated coefficient
Hi, I am trying to replicate the R's result for VCV matrix of estimated coefficients from linear model as below data(mtcars) model <- lm(mpg~disp+hp, data=mtcars) model_summ <-summary(model) MSE = mean(model_summ$residuals^2) vcov(model) Now I want to calculate the same thing manually, library(dplyr) X = as.matrix(mtcars[, c('disp', 'hp')] %>% mutate(Intercept =