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!










share|improve this question






















  • 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















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!










share|improve this question






















  • 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













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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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


















  • 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
















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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Landwehr

Reims

Schenkenzell