removing columns via subset throws unary invalid argument error
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
add a comment |
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
1
you don't need quotes in subset here
– rawr
Aug 7 '15 at 3:41
add a comment |
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
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
r subset
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
That was exactly what I needed
– Rilcon42
Aug 7 '15 at 15:27
add a comment |
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.
That didnt work for meobject gender was not foundpossibly because the column name in df1 issurveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53
1
Usecbind(df1,surveys["gender"])- there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38
add a comment |
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
});
}
});
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%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
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
That was exactly what I needed
– Rilcon42
Aug 7 '15 at 15:27
add a comment |
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
That was exactly what I needed
– Rilcon42
Aug 7 '15 at 15:27
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
That didnt work for meobject gender was not foundpossibly because the column name in df1 issurveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53
1
Usecbind(df1,surveys["gender"])- there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38
add a comment |
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.
That didnt work for meobject gender was not foundpossibly because the column name in df1 issurveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53
1
Usecbind(df1,surveys["gender"])- there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38
add a comment |
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.
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.
answered Aug 7 '15 at 3:43
David Robinson
59.2k9119148
59.2k9119148
That didnt work for meobject gender was not foundpossibly because the column name in df1 issurveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53
1
Usecbind(df1,surveys["gender"])- there's no reason to have such an odd looking variable name.
– thelatemail
Aug 7 '15 at 5:38
add a comment |
That didnt work for meobject gender was not foundpossibly because the column name in df1 issurveys$gender, it carries over from the other dataframe when I bound the two together
– Rilcon42
Aug 7 '15 at 3:53
1
Usecbind(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
add a comment |
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.
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%2f31869305%2fremoving-columns-via-subset-throws-unary-invalid-argument-error%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
1
you don't need quotes in subset here
– rawr
Aug 7 '15 at 3:41