removing columns via subset throws unary invalid argument error












1














I have a dataframe with rather odd column names (it is a combination of several other dataframes). Every time I try to subset and remove a column it gives me an error Error in -c("surveys$gender") : invalid argument to unary operator. Can someone explain why this is happening?



df1<-NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
surveys<-NULL
surveys$gender<-c(0,0,0,1,1)
df1<-as.data.frame(df1)

df1<-cbind(df1,surveys$gender)
male<-subset(df1,'surveys$gender'<1,select=-c('surveys$gender')) #trying to get only 0 and remove the gender column from the result









share|improve this question


















  • 1




    you don't need quotes in subset here
    – rawr
    Aug 7 '15 at 3:41
















1














I have a dataframe with rather odd column names (it is a combination of several other dataframes). Every time I try to subset and remove a column it gives me an error Error in -c("surveys$gender") : invalid argument to unary operator. Can someone explain why this is happening?



df1<-NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
surveys<-NULL
surveys$gender<-c(0,0,0,1,1)
df1<-as.data.frame(df1)

df1<-cbind(df1,surveys$gender)
male<-subset(df1,'surveys$gender'<1,select=-c('surveys$gender')) #trying to get only 0 and remove the gender column from the result









share|improve this question


















  • 1




    you don't need quotes in subset here
    – rawr
    Aug 7 '15 at 3:41














1












1








1







I have a dataframe with rather odd column names (it is a combination of several other dataframes). Every time I try to subset and remove a column it gives me an error Error in -c("surveys$gender") : invalid argument to unary operator. Can someone explain why this is happening?



df1<-NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
surveys<-NULL
surveys$gender<-c(0,0,0,1,1)
df1<-as.data.frame(df1)

df1<-cbind(df1,surveys$gender)
male<-subset(df1,'surveys$gender'<1,select=-c('surveys$gender')) #trying to get only 0 and remove the gender column from the result









share|improve this question













I have a dataframe with rather odd column names (it is a combination of several other dataframes). Every time I try to subset and remove a column it gives me an error Error in -c("surveys$gender") : invalid argument to unary operator. Can someone explain why this is happening?



df1<-NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
surveys<-NULL
surveys$gender<-c(0,0,0,1,1)
df1<-as.data.frame(df1)

df1<-cbind(df1,surveys$gender)
male<-subset(df1,'surveys$gender'<1,select=-c('surveys$gender')) #trying to get only 0 and remove the gender column from the result






r subset






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 7 '15 at 3:37









Rilcon42

2,56673165




2,56673165








  • 1




    you don't need quotes in subset here
    – rawr
    Aug 7 '15 at 3:41














  • 1




    you don't need quotes in subset here
    – rawr
    Aug 7 '15 at 3:41








1




1




you don't need quotes in subset here
– rawr
Aug 7 '15 at 3:41




you don't need quotes in subset here
– rawr
Aug 7 '15 at 3:41












2 Answers
2






active

oldest

votes


















0














Is this helpful?



male <- df1[df1[['surveys$gender']] < 1, ]
male[['surveys$gender']] <- NULL
male

a b c
1 1 4 0
2 2 5 9
3 3 2 0





share|improve this answer





















  • That was exactly what I needed
    – Rilcon42
    Aug 7 '15 at 15:27



















2














Change your subset line to:



df1 <- NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
df1$gender<-c(0,0,0,1,1)
male <- subset(df1, gender < 1, select = -gender)


That is, use bare column names rather than quotes.






share|improve this answer





















  • That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
    – Rilcon42
    Aug 7 '15 at 3:53






  • 1




    Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
    – thelatemail
    Aug 7 '15 at 5:38











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',
autoActivateHeartbeat: false,
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%2f31869305%2fremoving-columns-via-subset-throws-unary-invalid-argument-error%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Is this helpful?



male <- df1[df1[['surveys$gender']] < 1, ]
male[['surveys$gender']] <- NULL
male

a b c
1 1 4 0
2 2 5 9
3 3 2 0





share|improve this answer





















  • That was exactly what I needed
    – Rilcon42
    Aug 7 '15 at 15:27
















0














Is this helpful?



male <- df1[df1[['surveys$gender']] < 1, ]
male[['surveys$gender']] <- NULL
male

a b c
1 1 4 0
2 2 5 9
3 3 2 0





share|improve this answer





















  • That was exactly what I needed
    – Rilcon42
    Aug 7 '15 at 15:27














0












0








0






Is this helpful?



male <- df1[df1[['surveys$gender']] < 1, ]
male[['surveys$gender']] <- NULL
male

a b c
1 1 4 0
2 2 5 9
3 3 2 0





share|improve this answer












Is this helpful?



male <- df1[df1[['surveys$gender']] < 1, ]
male[['surveys$gender']] <- NULL
male

a b c
1 1 4 0
2 2 5 9
3 3 2 0






share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 7 '15 at 4:12









Whitebeard

2,52731324




2,52731324












  • That was exactly what I needed
    – Rilcon42
    Aug 7 '15 at 15:27


















  • That was exactly what I needed
    – Rilcon42
    Aug 7 '15 at 15:27
















That was exactly what I needed
– Rilcon42
Aug 7 '15 at 15:27




That was exactly what I needed
– Rilcon42
Aug 7 '15 at 15:27













2














Change your subset line to:



df1 <- NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
df1$gender<-c(0,0,0,1,1)
male <- subset(df1, gender < 1, select = -gender)


That is, use bare column names rather than quotes.






share|improve this answer





















  • That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
    – Rilcon42
    Aug 7 '15 at 3:53






  • 1




    Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
    – thelatemail
    Aug 7 '15 at 5:38
















2














Change your subset line to:



df1 <- NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
df1$gender<-c(0,0,0,1,1)
male <- subset(df1, gender < 1, select = -gender)


That is, use bare column names rather than quotes.






share|improve this answer





















  • That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
    – Rilcon42
    Aug 7 '15 at 3:53






  • 1




    Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
    – thelatemail
    Aug 7 '15 at 5:38














2












2








2






Change your subset line to:



df1 <- NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
df1$gender<-c(0,0,0,1,1)
male <- subset(df1, gender < 1, select = -gender)


That is, use bare column names rather than quotes.






share|improve this answer












Change your subset line to:



df1 <- NULL
df1$a<-c(1,2,3,4,5)
df1$b<-c(4,5,2,6,1)
df1$c<-c(0,9,0,6,3)
df1$gender<-c(0,0,0,1,1)
male <- subset(df1, gender < 1, select = -gender)


That is, use bare column names rather than quotes.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 7 '15 at 3:43









David Robinson

59.2k9119148




59.2k9119148












  • That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
    – Rilcon42
    Aug 7 '15 at 3:53






  • 1




    Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
    – thelatemail
    Aug 7 '15 at 5:38


















  • That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
    – Rilcon42
    Aug 7 '15 at 3:53






  • 1




    Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
    – thelatemail
    Aug 7 '15 at 5:38
















That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53




That didnt work for me object gender was not found possibly because the column name in df1 is surveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53




1




1




Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38




Use cbind(df1,surveys["gender"]) - there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31869305%2fremoving-columns-via-subset-throws-unary-invalid-argument-error%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

Coverage of Google Street View

Full-time equivalent

Surfing