What's the difference between using select + unlist from dplyr package and using the dollar sign?












10














I've been taking an online course in which the instructor always does the following to obtain, say, the column Col1 from a data.frame object Dat:



library(dplyr)
unlist(select(Dat, Col1))


Why not simply run Dat$Col1? I notice a difference in the "presentation" of both results, but is there any other significant divergence between the two forms? Any operation will result in the same product for both?










share|improve this question









New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 8




    Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
    – Rich Scriven
    2 days ago








  • 9




    ...but not well-versed enough to know of pull.
    – Henrik
    2 days ago








  • 4




    Touche. Maybe OP can take the instructor to school.
    – Rich Scriven
    2 days ago








  • 3




    Wow, he loads an entire new library for that?
    – cory
    2 days ago






  • 5




    The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
    – Henrik
    2 days ago


















10














I've been taking an online course in which the instructor always does the following to obtain, say, the column Col1 from a data.frame object Dat:



library(dplyr)
unlist(select(Dat, Col1))


Why not simply run Dat$Col1? I notice a difference in the "presentation" of both results, but is there any other significant divergence between the two forms? Any operation will result in the same product for both?










share|improve this question









New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 8




    Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
    – Rich Scriven
    2 days ago








  • 9




    ...but not well-versed enough to know of pull.
    – Henrik
    2 days ago








  • 4




    Touche. Maybe OP can take the instructor to school.
    – Rich Scriven
    2 days ago








  • 3




    Wow, he loads an entire new library for that?
    – cory
    2 days ago






  • 5




    The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
    – Henrik
    2 days ago
















10












10








10







I've been taking an online course in which the instructor always does the following to obtain, say, the column Col1 from a data.frame object Dat:



library(dplyr)
unlist(select(Dat, Col1))


Why not simply run Dat$Col1? I notice a difference in the "presentation" of both results, but is there any other significant divergence between the two forms? Any operation will result in the same product for both?










share|improve this question









New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I've been taking an online course in which the instructor always does the following to obtain, say, the column Col1 from a data.frame object Dat:



library(dplyr)
unlist(select(Dat, Col1))


Why not simply run Dat$Col1? I notice a difference in the "presentation" of both results, but is there any other significant divergence between the two forms? Any operation will result in the same product for both?







r dplyr






share|improve this question









New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Ben Bolker

132k11222309




132k11222309






New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









G. MonteiroG. Monteiro

513




513




New contributor




G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






G. Monteiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 8




    Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
    – Rich Scriven
    2 days ago








  • 9




    ...but not well-versed enough to know of pull.
    – Henrik
    2 days ago








  • 4




    Touche. Maybe OP can take the instructor to school.
    – Rich Scriven
    2 days ago








  • 3




    Wow, he loads an entire new library for that?
    – cory
    2 days ago






  • 5




    The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
    – Henrik
    2 days ago
















  • 8




    Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
    – Rich Scriven
    2 days ago








  • 9




    ...but not well-versed enough to know of pull.
    – Henrik
    2 days ago








  • 4




    Touche. Maybe OP can take the instructor to school.
    – Rich Scriven
    2 days ago








  • 3




    Wow, he loads an entire new library for that?
    – cory
    2 days ago






  • 5




    The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
    – Henrik
    2 days ago










8




8




Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
– Rich Scriven
2 days ago






Your instructor is probably just a fan of the tidyverse. Dat$Col1 is my preferred method for getting a column.
– Rich Scriven
2 days ago






9




9




...but not well-versed enough to know of pull.
– Henrik
2 days ago






...but not well-versed enough to know of pull.
– Henrik
2 days ago






4




4




Touche. Maybe OP can take the instructor to school.
– Rich Scriven
2 days ago






Touche. Maybe OP can take the instructor to school.
– Rich Scriven
2 days ago






3




3




Wow, he loads an entire new library for that?
– cory
2 days ago




Wow, he loads an entire new library for that?
– cory
2 days ago




5




5




The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
– Henrik
2 days ago






The rumours about the SO incident spread, and the instructor decided to gather every student. today he had started to select cigarettes without filter, and took a long, deep pull to compose himself for a minute. It was a mare’s nest. “Well, I have a crow to pluck with you, who did this?”, the teacher started. "between you and me: this is no funs. You better not cross me, or I will reduce your grades, every grade. Whichever way you slice it - period!" The students looked at each other. A complete farce. Happy new year every one - tally-ho!
– Henrik
2 days ago














1 Answer
1






active

oldest

votes


















9














(Posting comments as community wiki.)



These are not quite equivalent - unlist(select(.)) keeps (probably unwanted) names.



dd <- data.frame(Col1=c("abc","def"))
str(unlist(select(dd,Col1)))
## Factor w/ 2 levels "abc","def": 1 2
## - attr(*, "names")= chr [1:2] "Col11" "Col12"
str(dd$Col1)
## Factor w/ 2 levels "abc","def": 1 2


Your instructor is probably just a fan of the tidyverse (@RichScriven); pull(Dat, Col1) or (for extreme "tidiness") Dat %>% pull(Col1) would be more idiomatic (@Henrik). Dat$Col1 or Dat[["Col1"]] would be the base-R equivalents (the former is more convenient for interactive use, the latter is marginally safer for programming purposes since it won't do name-completion).



It hardly matters, but the tidyverse approaches are much slower.



microbenchmark(dd$Col1,dd[["Col1"]],pull(dd,Col1),unlist(select(dd,Col1)))
Unit: microseconds
expr min lq mean median uq
dd$Col1 5.296 10.9630 14.86871 13.4040 17.160
dd[["Col1"]] 7.870 9.6535 15.18874 11.8270 16.635
pull(dd, Col1) 44.160 108.7625 128.89342 117.8415 136.890
unlist(select(dd, Col1)) 601.480 1132.8240 1436.44178 1214.4420 1378.141
max neval cld
31.036 100 a
88.842 100 a
422.462 100 a
8796.964 100 b





share|improve this answer



















  • 2




    Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
    – Rui Barradas
    2 days ago






  • 1




    Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
    – lmo
    2 days ago











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
});


}
});






G. Monteiro is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54056096%2fwhats-the-difference-between-using-select-unlist-from-dplyr-package-and-using%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









9














(Posting comments as community wiki.)



These are not quite equivalent - unlist(select(.)) keeps (probably unwanted) names.



dd <- data.frame(Col1=c("abc","def"))
str(unlist(select(dd,Col1)))
## Factor w/ 2 levels "abc","def": 1 2
## - attr(*, "names")= chr [1:2] "Col11" "Col12"
str(dd$Col1)
## Factor w/ 2 levels "abc","def": 1 2


Your instructor is probably just a fan of the tidyverse (@RichScriven); pull(Dat, Col1) or (for extreme "tidiness") Dat %>% pull(Col1) would be more idiomatic (@Henrik). Dat$Col1 or Dat[["Col1"]] would be the base-R equivalents (the former is more convenient for interactive use, the latter is marginally safer for programming purposes since it won't do name-completion).



It hardly matters, but the tidyverse approaches are much slower.



microbenchmark(dd$Col1,dd[["Col1"]],pull(dd,Col1),unlist(select(dd,Col1)))
Unit: microseconds
expr min lq mean median uq
dd$Col1 5.296 10.9630 14.86871 13.4040 17.160
dd[["Col1"]] 7.870 9.6535 15.18874 11.8270 16.635
pull(dd, Col1) 44.160 108.7625 128.89342 117.8415 136.890
unlist(select(dd, Col1)) 601.480 1132.8240 1436.44178 1214.4420 1378.141
max neval cld
31.036 100 a
88.842 100 a
422.462 100 a
8796.964 100 b





share|improve this answer



















  • 2




    Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
    – Rui Barradas
    2 days ago






  • 1




    Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
    – lmo
    2 days ago
















9














(Posting comments as community wiki.)



These are not quite equivalent - unlist(select(.)) keeps (probably unwanted) names.



dd <- data.frame(Col1=c("abc","def"))
str(unlist(select(dd,Col1)))
## Factor w/ 2 levels "abc","def": 1 2
## - attr(*, "names")= chr [1:2] "Col11" "Col12"
str(dd$Col1)
## Factor w/ 2 levels "abc","def": 1 2


Your instructor is probably just a fan of the tidyverse (@RichScriven); pull(Dat, Col1) or (for extreme "tidiness") Dat %>% pull(Col1) would be more idiomatic (@Henrik). Dat$Col1 or Dat[["Col1"]] would be the base-R equivalents (the former is more convenient for interactive use, the latter is marginally safer for programming purposes since it won't do name-completion).



It hardly matters, but the tidyverse approaches are much slower.



microbenchmark(dd$Col1,dd[["Col1"]],pull(dd,Col1),unlist(select(dd,Col1)))
Unit: microseconds
expr min lq mean median uq
dd$Col1 5.296 10.9630 14.86871 13.4040 17.160
dd[["Col1"]] 7.870 9.6535 15.18874 11.8270 16.635
pull(dd, Col1) 44.160 108.7625 128.89342 117.8415 136.890
unlist(select(dd, Col1)) 601.480 1132.8240 1436.44178 1214.4420 1378.141
max neval cld
31.036 100 a
88.842 100 a
422.462 100 a
8796.964 100 b





share|improve this answer



















  • 2




    Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
    – Rui Barradas
    2 days ago






  • 1




    Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
    – lmo
    2 days ago














9












9








9






(Posting comments as community wiki.)



These are not quite equivalent - unlist(select(.)) keeps (probably unwanted) names.



dd <- data.frame(Col1=c("abc","def"))
str(unlist(select(dd,Col1)))
## Factor w/ 2 levels "abc","def": 1 2
## - attr(*, "names")= chr [1:2] "Col11" "Col12"
str(dd$Col1)
## Factor w/ 2 levels "abc","def": 1 2


Your instructor is probably just a fan of the tidyverse (@RichScriven); pull(Dat, Col1) or (for extreme "tidiness") Dat %>% pull(Col1) would be more idiomatic (@Henrik). Dat$Col1 or Dat[["Col1"]] would be the base-R equivalents (the former is more convenient for interactive use, the latter is marginally safer for programming purposes since it won't do name-completion).



It hardly matters, but the tidyverse approaches are much slower.



microbenchmark(dd$Col1,dd[["Col1"]],pull(dd,Col1),unlist(select(dd,Col1)))
Unit: microseconds
expr min lq mean median uq
dd$Col1 5.296 10.9630 14.86871 13.4040 17.160
dd[["Col1"]] 7.870 9.6535 15.18874 11.8270 16.635
pull(dd, Col1) 44.160 108.7625 128.89342 117.8415 136.890
unlist(select(dd, Col1)) 601.480 1132.8240 1436.44178 1214.4420 1378.141
max neval cld
31.036 100 a
88.842 100 a
422.462 100 a
8796.964 100 b





share|improve this answer














(Posting comments as community wiki.)



These are not quite equivalent - unlist(select(.)) keeps (probably unwanted) names.



dd <- data.frame(Col1=c("abc","def"))
str(unlist(select(dd,Col1)))
## Factor w/ 2 levels "abc","def": 1 2
## - attr(*, "names")= chr [1:2] "Col11" "Col12"
str(dd$Col1)
## Factor w/ 2 levels "abc","def": 1 2


Your instructor is probably just a fan of the tidyverse (@RichScriven); pull(Dat, Col1) or (for extreme "tidiness") Dat %>% pull(Col1) would be more idiomatic (@Henrik). Dat$Col1 or Dat[["Col1"]] would be the base-R equivalents (the former is more convenient for interactive use, the latter is marginally safer for programming purposes since it won't do name-completion).



It hardly matters, but the tidyverse approaches are much slower.



microbenchmark(dd$Col1,dd[["Col1"]],pull(dd,Col1),unlist(select(dd,Col1)))
Unit: microseconds
expr min lq mean median uq
dd$Col1 5.296 10.9630 14.86871 13.4040 17.160
dd[["Col1"]] 7.870 9.6535 15.18874 11.8270 16.635
pull(dd, Col1) 44.160 108.7625 128.89342 117.8415 136.890
unlist(select(dd, Col1)) 601.480 1132.8240 1436.44178 1214.4420 1378.141
max neval cld
31.036 100 a
88.842 100 a
422.462 100 a
8796.964 100 b






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago


























community wiki





2 revs
Ben Bolker









  • 2




    Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
    – Rui Barradas
    2 days ago






  • 1




    Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
    – lmo
    2 days ago














  • 2




    Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
    – Rui Barradas
    2 days ago






  • 1




    Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
    – lmo
    2 days ago








2




2




Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
– Rui Barradas
2 days ago




Since you mentioned it, pull(dd, Col1) is twice as fast as dd %>% pull(Col1). Tested with a much larger dd <- data.frame(Col1 = sample(c("abc", "def"), 1e6, TRUE)).
– Rui Barradas
2 days ago




1




1




Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
– lmo
2 days ago




Just to note, there's always the use.names argument to the base R function, unlist which will drop any unwanted names: unlist(select(.), use.names=FALSE).
– lmo
2 days ago










G. Monteiro is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















G. Monteiro is a new contributor. Be nice, and check out our Code of Conduct.













G. Monteiro is a new contributor. Be nice, and check out our Code of Conduct.












G. Monteiro is a new contributor. Be nice, and check out our Code of Conduct.
















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%2f54056096%2fwhats-the-difference-between-using-select-unlist-from-dplyr-package-and-using%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

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?