In a dpylr pipline how to use sample and seq?

0 votes

 I have a dataframe consisting of two columns set1 & set2, create a new variable that is a randomly selected value between set1 and set2 (inclusive and equal probability) using dplyr.

I got an error

library(tidyverse)

data_frame(set1 = 1:10, set2 = 11) %>% mutate(rand_btwn = base::sample(seq(set1, set2, by = 1), size = 1))

Apr 6, 2018 in Data Analytics by DataKing99
• 8,130 points
78 views

1 answer to this question.

0 votes

For avoiding rowwise(), I prefer to use map() in mutate

set.seed(123)
data_frame(set1 = 1:10, set2 = 15) %>%
  mutate(rand_btwn = map_int(map2(set1, set2, seq), sample, size = 1))

image

answered Apr 6, 2018 by DeepCoder786
• 1,720 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
1 answer

How to filter a data frame with dplyr and tidy evaluation in R?

Requires the use of map_df to run each model, ...READ MORE

answered May 16, 2018 in Data Analytics by DataKing99
• 8,130 points
119 views
0 votes
1 answer

How to sample n random rows per group in a dataframe?

You can assign a random ID to ...READ MORE

answered Jul 2, 2018 in Data Analytics by darklord
• 6,170 points
244 views
0 votes
1 answer

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

Structured query language (SQL) is a programming ...READ MORE

answered Aug 24, 2018 in Data Analytics by Anmol
• 3,620 points
132 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
105 views
0 votes
1 answer

With the help of tidyverse: how to rename a column to a variable name

With the help of Dplyr: rename function ...READ MORE

answered Apr 3, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Apr 3, 2018 by DeepCoder786 44 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
83 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
96 views
0 votes
1 answer

How to change mulitiple characters in a column to a date

Firstly we have to set dataf variable ...READ MORE

answered Apr 3, 2018 in Data Analytics by DeepCoder786
• 1,720 points
34 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
132 views