arm<-as.data.frame(matrix(c(1,1,1,2,2,6,7,4,9,10),ncol=2))
colnames(arm)<-c("a","b")
This is a dataset I created in R.
Now I want to rank the column b and group by column a.
The following piece of code is throwing this error, no matter what changes I make to the syntax(like adding [], "", etc...)
Error in sqliteSendQuery(con, statement, bind.data) : error in statement: near "(": syntax error
I was using "sqldf" package.
arm2<-sqldf("select a,
b,
rank() over (partition by a order by b) as rank1
from arm")
Then I installed the RH2 package and it started to throw the following error:
Error in .verify.JDBC.result(s, "Unable to execute JDBC statement ", statement) : Unable to execute JDBC statement select a, b, rank() over (partition by a order by b) as rank1 from arm (Function "rank" not found; SQL statement: select a, b, rank() over (partition by a order by b) as rank1 from arm [90022-175])
How to use rank() over function of sql in sqldf package of R?
arm$rank1 <- unlist(with(arm, tapply(b, a, rank)))
, for example. – Secrecyunlist(tapply(...))
would be better replaced byave
, so it is isn't dependent on the order of the dataset. – Zahavi