I am connecting a MySQL data base with dplyr
and handle the data with dplyr
and the %>%
operatot subsequently.
conDplyr <- src_mysql(user = db_user, password = db_pw, dbname = db_name, host = db_host, port = some_port)
As long as I select a certain number of columns but all, it works!
dat <- conDplyr %>%
tbl('table_name') %>%
select(c1, c2, c3, c4) %>%
filter(!is.null(c4))
Now, I ran over a use case, in which I need to select all columns (whole table). All tutorials I found (about dplyr
) handled this by selecting the whole dataframe (which I do not have)
some_dataframe <- ...
select(some_dataframe)
I have not found any suggestions in combination with databases. Perhaps the day was too long. Does anybody could help me please?
Best Rob
conDplyr <- src_mysql(...)
dat <- conDplyr %>%
tbl('table_name') %>%
select(everything()) %>%
filter(!is.null(ean))
works just fine. Thanks! If I leave out the select the query results in an error (non-defined columns selected). Again, I did not just want to work with a already existing data frame, but with a table queried from a database, that`s why I am have to do, correct me if I am wrong, an select.
To pick out single or multiple columns use the select() function. The select() function expects a dataframe as it's first input ('argument', in R language), followed by the names of the columns you want to extract with a comma between each name.
Select Variables by Index PositionThe select() function of dplyr package is used to select variable names from the R data frame. Use this function if you wanted to select the data frame variables by index or position.
dplyr is a R package that provides a set of grammar based functions to transform data. Compared to using SQL, it's much easier to construct and much easier to read what's constructed.
As @AntoniosK pointed out I do not know why you would like to do that. However, have you tried everything
?:
some_dataframe <- ...
select(everything())
For instance:
select(iris, everything()) # or
iris %>% select(everything())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With