如何选择dplyr / sql中的所有列? [英] How to select all columns in dplyr/sql?
问题描述
我正在将MySQL数据库与 dplyr
连接,并使用 dplyr
和<$ c $处理数据c>%&%;%随后操作。
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)
dat <- conDplyr %>%
tbl('table_name') %>%
select(c1, c2, c3, c4) %>%
filter(!is.null(c4))
现在,我遍历了一个用例,其中需要选择所有列(整个表)。我发现的所有教程(大约 dplyr
)都是通过选择整个数据框(我没有的)来解决的。
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?
最佳抢劫
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.
推荐答案
正如@AntoniosK指出的,我不知道您为什么要这样做。但是,您是否尝试过一切
?:
As @AntoniosK pointed out I do not know why you would like to do that. However, have you tried everything
?:
some_dataframe <- ...
select(everything())
例如:
select(iris, everything()) # or
iris %>% select(everything())
这篇关于如何选择dplyr / sql中的所有列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!