R: No duplicate keys, data won't spread
up vote
0
down vote
favorite
I'm trying to reshape a data set from long to wide on two keys. I keep getting the message Aggregation function missing: defaulting to length.
My dataset looks like this:
School.Name var val year
1 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2010-11
2 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2011-12
3 A G COX MIDDLE American.Indian.Alaska.Native.Students 2 2012-13
4 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2013-14
5 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2014-15
6 A G COX MIDDLE American.Indian.Alaska.Native.Students 0 2015-16
The original variables had year names in them (formatted as race.year, so I had white.2012_13, white.2013_14, etc.). The first step I took was formatting from wide to long, and pulling year from the variable name. I want my data set to be organized by school and year, with individual demographic categories as variables, and counts as the values. I've been using dcast as such:
dcast(dem, School.Name + year ~ var, value.var = "val")
But I'm only getting the length. All help is appreciated!
r dataframe tidyverse tidyr reshape2
add a comment |
up vote
0
down vote
favorite
I'm trying to reshape a data set from long to wide on two keys. I keep getting the message Aggregation function missing: defaulting to length.
My dataset looks like this:
School.Name var val year
1 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2010-11
2 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2011-12
3 A G COX MIDDLE American.Indian.Alaska.Native.Students 2 2012-13
4 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2013-14
5 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2014-15
6 A G COX MIDDLE American.Indian.Alaska.Native.Students 0 2015-16
The original variables had year names in them (formatted as race.year, so I had white.2012_13, white.2013_14, etc.). The first step I took was formatting from wide to long, and pulling year from the variable name. I want my data set to be organized by school and year, with individual demographic categories as variables, and counts as the values. I've been using dcast as such:
dcast(dem, School.Name + year ~ var, value.var = "val")
But I'm only getting the length. All help is appreciated!
r dataframe tidyverse tidyr reshape2
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
1
Did you tryreshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?
– iod
Nov 9 at 4:14
Have you triedtidyr::spread()?
– dmca
Nov 9 at 7:05
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to reshape a data set from long to wide on two keys. I keep getting the message Aggregation function missing: defaulting to length.
My dataset looks like this:
School.Name var val year
1 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2010-11
2 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2011-12
3 A G COX MIDDLE American.Indian.Alaska.Native.Students 2 2012-13
4 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2013-14
5 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2014-15
6 A G COX MIDDLE American.Indian.Alaska.Native.Students 0 2015-16
The original variables had year names in them (formatted as race.year, so I had white.2012_13, white.2013_14, etc.). The first step I took was formatting from wide to long, and pulling year from the variable name. I want my data set to be organized by school and year, with individual demographic categories as variables, and counts as the values. I've been using dcast as such:
dcast(dem, School.Name + year ~ var, value.var = "val")
But I'm only getting the length. All help is appreciated!
r dataframe tidyverse tidyr reshape2
I'm trying to reshape a data set from long to wide on two keys. I keep getting the message Aggregation function missing: defaulting to length.
My dataset looks like this:
School.Name var val year
1 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2010-11
2 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2011-12
3 A G COX MIDDLE American.Indian.Alaska.Native.Students 2 2012-13
4 A G COX MIDDLE American.Indian.Alaska.Native.Students 3 2013-14
5 A G COX MIDDLE American.Indian.Alaska.Native.Students 1 2014-15
6 A G COX MIDDLE American.Indian.Alaska.Native.Students 0 2015-16
The original variables had year names in them (formatted as race.year, so I had white.2012_13, white.2013_14, etc.). The first step I took was formatting from wide to long, and pulling year from the variable name. I want my data set to be organized by school and year, with individual demographic categories as variables, and counts as the values. I've been using dcast as such:
dcast(dem, School.Name + year ~ var, value.var = "val")
But I'm only getting the length. All help is appreciated!
r dataframe tidyverse tidyr reshape2
r dataframe tidyverse tidyr reshape2
asked Nov 9 at 3:40
jrd45
1
1
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
1
Did you tryreshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?
– iod
Nov 9 at 4:14
Have you triedtidyr::spread()?
– dmca
Nov 9 at 7:05
add a comment |
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
1
Did you tryreshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?
– iod
Nov 9 at 4:14
Have you triedtidyr::spread()?
– dmca
Nov 9 at 7:05
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
1
1
Did you try
reshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?– iod
Nov 9 at 4:14
Did you try
reshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?– iod
Nov 9 at 4:14
Have you tried
tidyr::spread()?– dmca
Nov 9 at 7:05
Have you tried
tidyr::spread()?– dmca
Nov 9 at 7:05
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219530%2fr-no-duplicate-keys-data-wont-spread%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'm not getting any error with this data and your code. Can you provide a full reproducible example of the problem?
– iod
Nov 9 at 4:11
1
Did you try
reshape2::dcast(df,School.Name + year ~ var,sum,value.var="val")?– iod
Nov 9 at 4:14
Have you tried
tidyr::spread()?– dmca
Nov 9 at 7:05