All Questions
72 questions
0
votes
3
answers
40
views
Expand the data set to include all combinations of the values of the variables using R
I have the following snippet of my data set that consists of thousands of observations
and I want to expand this data set using R so as to include all combiations of the first two columns
that is, I ...
3
votes
5
answers
109
views
R Expand Data Frame List
DATA = data.frame(STUDENT = c(1:3),
G1 = c(2,2,1),
G2 = c(3,5,4))
DATA1 = data.frame(STUDENT1 = c(0,1,1,0,0),
STUDENT2 = c(0,1,1,1,1),
...
1
vote
1
answer
16
views
Create a dataframe by fixing rows in one column and repeating other columns
Lets say I have three variables:
var1<-c(101,102,103,104)
var2<-c("AB","XY")
var3<-c(1,2)
X<-expand.grid(var1,var2,var3)
X
Above code gives this output
Var1 Var2 ...
0
votes
2
answers
98
views
R: grouping and expanding the data.frame to include only possible pairs of names in a column
My goal is to expand my data.frame in R to include possible combinations (but not all possible combinations) from a column in R. Similar to the expand.grid command, but that function gives you all ...
2
votes
1
answer
34
views
how expand pivoted dataframe?
I want to get combination of all parameters after pivoting data frame. I have data frame like this:
df <- data.frame(parameter = c(rep("X",5), rep("Y",3)), value=c(letters[1:5],...
3
votes
3
answers
82
views
Get all level combinations for each group
I have a list of customer IDs, each with a list of unique products they used. There can theoretically be up to ~150 unique products.
df <- tibble(ID = c(1,1,1,2,2,3,3,4),
prod = c(&...
1
vote
3
answers
90
views
How to use expand_grid to replicate values?
I have the following two data frame.
First, I have the occupations data frame. Sample data frame below
state <- c("00","00","32","32")
codetype <- c(&...
1
vote
2
answers
68
views
How to get the cartesian product?
I have a data frame like this:
plazo
monto
20
2
50
3
I need to add a rows for values between 1 to the value of plazo and expand my dataframe like below;
plazo
monto
Semana
20
2
1
20
2
2
20
2
3
20
2
…
...
2
votes
3
answers
178
views
How to expand rows and fill in the numbers between given start and end
I have this data frame:
df <- tibble(x = c(1, 10))
x
<dbl>
1 1
2 10
I want this:
x
<int>
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 ...
2
votes
3
answers
53
views
Repeat data by group per year
I have a data frame with more than thousand rows like this.
org year country
a 2010 US
a 2012 UK
b 2014 Mexico
b 2014 CHile
b 2015 Brazil
And I would like to make my data like this. I want my data to ...
0
votes
1
answer
29
views
Replacing Content of a column with part of that column's content
I'd like to replace the content of a column in a data frame with only a specific word in that column.
The column always looks like this:
Place(fullName='Würzburg, Germany', name='Würzburg', type='city'...
0
votes
2
answers
172
views
How to expand and count consecutively in R?
How do you expand a dataset and count consecutively by year?
Specifically, my dataset has 15 rows and 4 columns: the firm ID, sector code, year and month. This data has 15 monthly information over 2 ...
2
votes
1
answer
154
views
Expanding a column with row of NA when there is no match in R
I am trying to "clean" a dataset that has many "empty" rows deleted, however, I want these empty rows back (and adding NA). Here is a toy dataset:
values <- rnorm(12)
data <- ...
0
votes
1
answer
147
views
`Error in seq.int` while expanding dataframe using start and end dates
*edit: I have provided dput() sample data at the bottom of page.
I have a large dataframe that I am trying to expand. Specifically, I want to use the start and end date columns to produce a row for ...
1
vote
1
answer
418
views
R - Expand dataframe to create panel data
I have a dataset where I observe individuals for different years (e.g., individual 1 is observed in 2012 and 2014, while individuals 2 and 3 are only observed in 2016). I would like to expand the data ...