Generating Row and Column Names when using R UDF
I am reposting the query I that started on vertica-forums.com (http://vertica-forums.com/viewtopic.php?f=62&t=1158) Hi, I am trying to use the R UDF to create a cross tab and have given the R function and the Vertica commands below. generateCrosstab <- function(x) { var1 = x[,1] var2 = x[,2] crossTab <- as.data.frame.matrix(table(var1,var2)) crossTab } crossTab_factory <- function() { inlist <- rep("int", 2) outlist <- c("int", "int") list(name=generateCrosstab, udxtype=c("transform"), intype=inlist, outtype=outlist) } DROP LIBRARY crossTab CASCADE; CREATE LIBRARY crossTab AS '/home/dbadmin/test/crossTab.r' LANGUAGE 'R'; CREATE TRANSFORM FUNCTION generateCrosstab AS NAME 'crossTab_factory' LIBRARY crossTab ; SELECT generateCrosstab(column1, column2) OVER() FROM testdb.table; This query generates the following output: col0 | col1 --------+-------- 466881 | 655735 21047 | 28336 (2 rows) Is there any way to generate the row names and the column names? I have given an example of what I am looking for: setosa versicolor virginica setosa 50 0 0 versicolor 0 50 0 virginica 0 0 50 Would appreciate any help on this? Thank you. Ravi
0
Comments