Questions tagged as 'dplyr'

1
answer

Select first lines depending on group efficiently

Suppose I have the following database set.seed(100) base <- expand.grid(grupo = c("a", "b", "c", "d"), score = runif(100)) And I want to select the lines with the lowest score depending on the group according to the table below:...
asked by 28.01.2015 / 13:50
2
answers

Direct (and beautiful) solution for storing base using dplyr

I have the following default basis: df <- data.frame( lead_15 = c(1,0,0,0,0,1,0,0,1,0,0,0,0,0,1), lead_30 = c(0,0,0,1,0,0,1,1,0,1,0,0,0,1,0), lead_60 = c(0,1,0,0,1,0,0,0,0,0,1,1,0,0,0), inib_15 = c(1,0,0,0,0,0,0,0,1,0,0,0,0,0,0),...
asked by 16.02.2017 / 20:31
2
answers

Select multiple rows from a data.frame, from the largest values R

I have the following date.frame in R: df <- data.frame(x = c(10,10,2,3,4,8,8,8), y = c(5,4,6,7,8,3,2,4)) df x y 1 10 5 2 10 4 3 2 6 4 3 7 5 4 8 6 8 3 7 8 2 8 8 4 First point : I would like to get all rows conta...
asked by 13.06.2017 / 18:56
2
answers

Dplyr and gsub: how to replace excerpts from one column to another

I have the following data-frame: xis <- data.frame(x1=c("**alo.123", "**alo.132", "**alo.199"), x2=c("sp", "mg", "rj"), x3=c(NA)) I would like to create a new column using gsub as follows: x3[1] <- gsub("alo", xis$x2[1], xis$x1[1])...
asked by 09.10.2014 / 16:20
1
answer

Rearrange data frame in a list using dplyr in R

This is my dataframe: dput(df) structure(list(ind = structure(c(16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 16437, 1...
asked by 16.09.2018 / 22:29
1
answer

How to use dplyr within a function?

Let's say I wanted to create a function that internally uses some functions of the dplyr or any tidyverse that use this type of syntax. By way of illustration: exemplo <- function(df, predicado, sumario) { df %>% filter(predicad...
asked by 29.06.2018 / 16:40
1
answer

Including columns in a dataframe in R using a rule

This is my dataframe: df<-as.data.frame(matrix(rexp(200, rate=.1), ncol=10)) colnames(df)<-c("one","two","three","four","five","six","seven","eight","nine","ten") This is the index I will use as an example: index<-c(1,2,3,4,5,6,7...
asked by 20.09.2018 / 00:00
1
answer

Creating a dataframe based on two other dataframes using dplyr in R

These are my dataframes: df<- as.data.frame(matrix(rexp(200),, 25)) colnames(df)<-c("A","B","C","D","E","F","G","H","I","J", "K","L","M","N","O","P","Q","R","S","T", "U","V","X","Z","W") df.new<-as.data.frame(matr...
asked by 23.09.2018 / 04:36
1
answer

Graph of interaction in ggplot2

I'm trying to adapt some of the standard R graphics to the ggplot2 style. One of the charts I want to do this is the interaction graph in a linear model fit study. The following data were taken from Example 9-1 in Douglas C. Montgomery...
asked by 15.12.2016 / 19:45
3
answers

R: How to count and sum the amount of a given "factor" in the observations (rows) of a data.frame?

Expensive, I would like to get the amount of "yes" (factor) in each row of a data.frame, like the one below. Would anyone know what arguments I would have to use to do this with the "mutate"? I tried it in different ways and I could not. I tried...
asked by 22.03.2018 / 22:20