Error: No Such Column using SQLDF

前端 未结 3 1976
时光说笑
时光说笑 2021-01-05 22:19

Below are the scripts

> library(sqldf)
> turnover = read.csv(\"turnover.csv\")
> names(turnover)
[1] \"Report.Date\"       \"PersID\"            \"S         


        
3条回答
  •  孤街浪徒
    2021-01-05 22:38

    There is no need to change column names.

    Starting with RSQLite 1.0.0 and sqldf 0.4-9 dots in column names are no longer translated to underscores. https://code.google.com/p/sqldf/

    We only need to write the SQL statement between single quotes, and the column names including dots between double quotes or backticks/backquotes interchangeably.

    Two examples:

    require(sqldf)
    # 1
    turnover <- data.frame(Status = c("A", "B", "C"), 
                           Current.Hire.Date = c("4/10/10", "13/11/10", "1/7/13"))
    sqldf('select Status, "Current.Hire.Date" from turnover') 
    
    #2. Double quotes and backticks interchangeably    
    sqldf('select Species, avg("Sepal.Length") `Sepal.Length`, 
       avg("Sepal.Width") `Sepal.Width` from iris group by Species')
    

    One more way to achieve the solution

    #3 Using square brackets 
    sqldf('select Species, avg([Sepal.Length]) `Sepal.Length`, 
       avg([Sepal.Width])  `Sepal.Width` from iris group by Species')
    

提交回复
热议问题