Timeline for Drop data frame columns by name
Current License: CC BY-SA 4.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 6, 2023 at 9:56 | comment | added | cmbarbu |
If column names are "weird", for example with spaces etc. you can also use within(DF,rm(list=c("x","z")))
|
|
| Apr 4, 2021 at 20:09 | comment | added | J. Mini |
Two other major benefits of within: You do not need to pass a drop=FALSE argument and rm will warn you if the column that you are attempting to delete is missing. [ is not so kind.
|
|
| Mar 18, 2021 at 1:43 | comment | added | J. Mini |
@HSchmale df<-data.frame(x=1:3,y=4:6,x=7:9) is valid, but the last column becomes x.1. I've only seen duplicate names in lists. To get it in a data frame, you need to pass the check.names = FALSE argument.
|
|
| Jan 3, 2019 at 19:26 | comment | added | HSchmale | @MilesErickson How often would one encounter a dataframe with duplicate names in it? | |
| Dec 14, 2018 at 6:54 | history | edited | Max Ghenis | CC BY-SA 4.0 |
Removed `with=FALSE` given this feature is now in production.
|
| Dec 13, 2018 at 13:45 | comment | added | Joris Meys |
@MilesErickson Problem is that you rely on a function within() which is powerful but also uses NSE. The note on the help page states clearly that for programming sufficient care should be used.
|
|
| May 23, 2017 at 12:18 | history | edited | URL Rewriter Bot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
| Mar 10, 2017 at 22:23 | comment | added | Max Ghenis |
@MichaelChirico to clarify, it removes neither but seems to change the data's values. One has bigger problems if this is the case, but here's an example: df <- data.frame(x = 1, y = 2); names(df) <- c("x", "x"); within(df, rm(x)) returns data.frame(x = 2, x = 2).
|
|
| Nov 22, 2016 at 22:54 | history | edited | MichaelChirico | CC BY-SA 3.0 |
added 233 characters in body
|
| Jul 15, 2016 at 19:51 | comment | added | MichaelChirico |
Note that within(df, rm(x)) will not work if there are duplicate columns named x in df.
|
|
| Jul 7, 2016 at 21:04 | history | edited | Max Ghenis | CC BY-SA 3.0 |
Simplified first line
|
| Apr 5, 2016 at 17:58 | history | edited | Max Ghenis | CC BY-SA 3.0 |
Removed "easier" (not really easier)
|
| Oct 2, 2015 at 1:00 | comment | added | Miles Erickson |
within(df, rm(x)) is by far the cleanest solution. Given that this is a possibility, every other answer seems unnecessarily complicated by an order of magnitude.
|
|
| May 10, 2015 at 21:43 | history | edited | Max Ghenis | CC BY-SA 3.0 |
Add inline code formatting
|
| Sep 30, 2013 at 18:05 | history | edited | Matt Dowle | CC BY-SA 3.0 |
Added :=NULL syntax
|
| Sep 28, 2013 at 22:28 | history | answered | Max Ghenis | CC BY-SA 3.0 |