Get variables names from a data frame in a vectorHow to join (merge) data frames (inner, outer, left, right)Grouping functions (tapply, by, aggregate) and the *apply familyDrop data frame columns by nameR: losing column names when adding rows to an empty data frameHow to succinctly write a formula with many variables from a data frame?Convert the values in a column into row names in an existing data frame in RConvert a row of a data frame to vectorConvert Named Character Vector to data.frameDynamically select data frame columns using $ and a vector of column namesInsert alternating vectors into data frame
What stroke width Instagram is using for its icons and how to get same results?
c++ what does , means after if
iMac 27" 2017 memory upgrade question
Why was Thor doubtful about his worthiness to Mjolnir?
Run script for 10 times until meets the condition, but break the loop if it meets the condition during iteration
How to make a language evolve quickly?
Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?
"Right on the tip of my tongue" meaning?
Is it a bad idea to replace pull-up resistors with hard pull-ups?
Drawing lines to nearest point
Unable to execute two commands in Startup Applications
What to do if SUS scores contradict qualitative feedback?
How to compact two the parabol commands in the following example?
Why was castling bad for white in this game, and engine strongly prefered trading queens?
Smallest Guaranteed hash collision cycle length
Can you book a one-way ticket to the UK on a visa?
Why didn't Aeroflot Flight 1492 dump its fuel first?
Why can't RGB or bicolour LEDs produce a decent yellow?
Is the schwa sound consistent?
Meaning of「〜てみたいと思います」
How do I tell my supervisor that he is choosing poor replacements for me while I am on maternity leave?
The CompuTaria Quest - A young Wizard's journey
How can I answer high-school writing prompts without sounding weird and fake?
How could a Lich maintain the appearance of being alive without magic?
Get variables names from a data frame in a vector
How to join (merge) data frames (inner, outer, left, right)Grouping functions (tapply, by, aggregate) and the *apply familyDrop data frame columns by nameR: losing column names when adding rows to an empty data frameHow to succinctly write a formula with many variables from a data frame?Convert the values in a column into row names in an existing data frame in RConvert a row of a data frame to vectorConvert Named Character Vector to data.frameDynamically select data frame columns using $ and a vector of column namesInsert alternating vectors into data frame
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I can obtain the names of my variables of a data frame with the command "names (df)". It gives say:
#[1] "V1" "V2" "V3"
But I would like to obtain a vector, something like this:
c("V1", "V2", "V3")
Is this possible in R?
Thanks in advance for your response
Richard
r vector names
add a comment |
I can obtain the names of my variables of a data frame with the command "names (df)". It gives say:
#[1] "V1" "V2" "V3"
But I would like to obtain a vector, something like this:
c("V1", "V2", "V3")
Is this possible in R?
Thanks in advance for your response
Richard
r vector names
1
I'm not sure to understand.names(df)is the vectorc("V1", "V2", "V3"). If you want to printc("V1", "V2", "V3"), you can dodput(names(df)).
– Stéphane Laurent
Mar 23 at 11:30
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37
add a comment |
I can obtain the names of my variables of a data frame with the command "names (df)". It gives say:
#[1] "V1" "V2" "V3"
But I would like to obtain a vector, something like this:
c("V1", "V2", "V3")
Is this possible in R?
Thanks in advance for your response
Richard
r vector names
I can obtain the names of my variables of a data frame with the command "names (df)". It gives say:
#[1] "V1" "V2" "V3"
But I would like to obtain a vector, something like this:
c("V1", "V2", "V3")
Is this possible in R?
Thanks in advance for your response
Richard
r vector names
r vector names
edited Mar 23 at 11:56
NelsonGon
4,8864934
4,8864934
asked Mar 23 at 11:28
R. LadweinR. Ladwein
63
63
1
I'm not sure to understand.names(df)is the vectorc("V1", "V2", "V3"). If you want to printc("V1", "V2", "V3"), you can dodput(names(df)).
– Stéphane Laurent
Mar 23 at 11:30
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37
add a comment |
1
I'm not sure to understand.names(df)is the vectorc("V1", "V2", "V3"). If you want to printc("V1", "V2", "V3"), you can dodput(names(df)).
– Stéphane Laurent
Mar 23 at 11:30
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37
1
1
I'm not sure to understand.
names(df) is the vector c("V1", "V2", "V3"). If you want to print c("V1", "V2", "V3"), you can do dput(names(df)).– Stéphane Laurent
Mar 23 at 11:30
I'm not sure to understand.
names(df) is the vector c("V1", "V2", "V3"). If you want to print c("V1", "V2", "V3"), you can do dput(names(df)).– Stéphane Laurent
Mar 23 at 11:30
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37
add a comment |
1 Answer
1
active
oldest
votes
It is possible and you can just make a new vector with the names like this:
x <- names(df)
..and the names will be stored in vector x
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%2f55313255%2fget-variables-names-from-a-data-frame-in-a-vector%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is possible and you can just make a new vector with the names like this:
x <- names(df)
..and the names will be stored in vector x
add a comment |
It is possible and you can just make a new vector with the names like this:
x <- names(df)
..and the names will be stored in vector x
add a comment |
It is possible and you can just make a new vector with the names like this:
x <- names(df)
..and the names will be stored in vector x
It is possible and you can just make a new vector with the names like this:
x <- names(df)
..and the names will be stored in vector x
answered Mar 23 at 11:39
OkaOka
77229
77229
add a comment |
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.
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%2f55313255%2fget-variables-names-from-a-data-frame-in-a-vector%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
I'm not sure to understand.
names(df)is the vectorc("V1", "V2", "V3"). If you want to printc("V1", "V2", "V3"), you can dodput(names(df)).– Stéphane Laurent
Mar 23 at 11:30
Thank you very much. It's exactly that I need !
– R. Ladwein
Mar 23 at 11:37