hi all i have a function that uses two inputs, say xdata and ydata. An example is the following, simple1<-function(xdata,ydata) { ofit<-lm(ydata~xdata) list(ofit) } say i use arbitray number for xdata and ydata such that D = x1 x2 y 1 1 10 2 6 6 3 10 7 x<-D[,1:2] and y<-D[,3] if one uses these inputs and rund the program we get the following:>simple(xdata=x,ydata=y)Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type why does this happen! i can get results if i change the program as follows: simple2<-function(xdata,ydata) { ofit<-lm(as.matrix(ydata)~as.matrix(xdata)) list(ofit) } but then the variable names, if they exist, are not preserved. how can i preserve these names. the results are now:> simple2(xdata=x,ydata=y)[[1]] Call: lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) Coefficients: (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 -6 21 -5 i've tried converting xdata and ydata to data frames but i still get errors. simple3<-function(xdata,ydata) { xdata<-as.data.frame(xdata) ydata<-as.data.frame(ydata) ofit<-lm(ydata~xdata) list(ofit) } i.e.> simple3(xdata=x,ydata=y)Error in model.frame(formula, rownames, variables, varnames, extras, extranames, : invalid variable type please help! thanking you in advance *** allan
Hello, I have no errors with simple1: d <- matrix(c(1,2,3,1,6,10,10,6,7),ncol=3) colnames(d) <- c("one", "two", "three") x<- d[,c(1,2)] y<-d[,3]> y[1] 10 6 7> simple1(x,y)[[1]] Call: lm(formula = ydata ~ xdata) Coefficients: (Intercept) xdataone xdatatwo -6 21 -5 With: y <-d[,3, drop=FALSE]> y[,1] [1,] 10 [2,] 6 [3,] 7> simple1(x,y)[[1]] Call: lm(formula = ydata ~ xdata) Coefficients: (Intercept) xdataone xdatatwo -6 21 -5 You have an error with function simple, which you have not shown! (you have only shown function simple1, simple2 and simple3) Look at simple3 now: simple3<-function(xdata,ydata) { datas<-data.frame(xdata=xdata,ydata=ydata) ofit<-lm(ydata~xdata, data=datas) list(ofit) }> simple3(x,y)[[1]] Call: lm(formula = ydata ~ xdata, data = datas) Coefficients: (Intercept) xdataone xdatatwo -6 21 -5 Best, Matthias> -----Urspr?ngliche Nachricht----- > Von: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] Im Auftrag von Clark Allan > Gesendet: Donnerstag, 24. Februar 2005 10:17 > An: r-help at stat.math.ethz.ch > Betreff: [R] r: functions > > > hi all > > > i have a function that uses two inputs, say xdata and ydata. > An example is the following, > > simple1<-function(xdata,ydata) > { > ofit<-lm(ydata~xdata) > list(ofit) > } > > say i use arbitray number for xdata and ydata such that > > D = > x1 x2 y > 1 1 10 > 2 6 6 > 3 10 7 > > > x<-D[,1:2] > > and > > y<-D[,3] > > if one uses these inputs and rund the program we get the following: > > >simple(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, > extras, extranames, : > invalid variable type > > why does this happen! > > i can get results if i change the program as follows: > > simple2<-function(xdata,ydata) > { > ofit<-lm(as.matrix(ydata)~as.matrix(xdata)) > list(ofit) > } > > but then the variable names, if they exist, are not > preserved. how can i preserve these names. > > the results are now: > > > simple2(xdata=x,ydata=y) > [[1]] > > Call: > lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) > > Coefficients: > (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 > -6 21 -5 > > i've tried converting xdata and ydata to data frames but i > still get errors. > > simple3<-function(xdata,ydata) > { > xdata<-as.data.frame(xdata) > ydata<-as.data.frame(ydata) > ofit<-lm(ydata~xdata) > list(ofit) > } > > i.e. > > > simple3(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, > extras, extranames, : > invalid variable type > > please help! > > thanking you in advance > > *** > allan >
There was a similar question about one week ago regarding the use of "table(x,y)". One approach could be to use the following: simple1 <- function(xdata, ydata){ ofit <- substitute(lm(ydata~xdata)) list(eval.parent(ofit)) } ############# simple1(xdata=x, ydata=y) lm(y~x) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Clark Allan" <Allan at stats.uct.ac.za> To: <r-help at stat.math.ethz.ch> Sent: Thursday, February 24, 2005 10:16 AM Subject: [R] r: functions> hi all > > > i have a function that uses two inputs, say xdata and ydata. An > example > is the following, > > simple1<-function(xdata,ydata) > { > ofit<-lm(ydata~xdata) > list(ofit) > } > > say i use arbitray number for xdata and ydata such that > > D > x1 x2 y > 1 1 10 > 2 6 6 > 3 10 7 > > > x<-D[,1:2] > > and > > y<-D[,3] > > if one uses these inputs and rund the program we get the following: > >>simple(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > invalid variable type > > why does this happen! > > i can get results if i change the program as follows: > > simple2<-function(xdata,ydata) > { > ofit<-lm(as.matrix(ydata)~as.matrix(xdata)) > list(ofit) > } > > but then the variable names, if they exist, are not preserved. how > can i > preserve these names. > > the results are now: > >> simple2(xdata=x,ydata=y) > [[1]] > > Call: > lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) > > Coefficients: > (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 > -6 21 -5 > > i've tried converting xdata and ydata to data frames but i still get > errors. > > simple3<-function(xdata,ydata) > { > xdata<-as.data.frame(xdata) > ydata<-as.data.frame(ydata) > ofit<-lm(ydata~xdata) > list(ofit) > } > > i.e. > >> simple3(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > invalid variable type > > please help! > > thanking you in advance > > *** > allan--------------------------------------------------------------------------------> ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html
hi all i worked it out. the following code seems to work. thanx for those who replied to previous questions. simple1<-function(xdata,ydata) { DATA<-data.frame(ydata,xdata) ofit<-summary(lm(ydata~.,data=DATA)) list(ofit) } simple1(x,y)> simple1(x,y)[[1]] Call: lm(formula = ydata ~ ., data = DATA) Coefficients: (Intercept) x1 x2 -6 21 -5 *** allan Clark Allan wrote:> > hi all > > i have a function that uses two inputs, say xdata and ydata. An example > is the following, > > simple1<-function(xdata,ydata) > { > ofit<-lm(ydata~xdata) > list(ofit) > } > > say i use arbitray number for xdata and ydata such that > > D > x1 x2 y > 1 1 10 > 2 6 6 > 3 10 7 > > x<-D[,1:2] > > and > > y<-D[,3] > > if one uses these inputs and rund the program we get the following: > > >simple(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > invalid variable type > > why does this happen! > > i can get results if i change the program as follows: > > simple2<-function(xdata,ydata) > { > ofit<-lm(as.matrix(ydata)~as.matrix(xdata)) > list(ofit) > } > > but then the variable names, if they exist, are not preserved. how can i > preserve these names. > > the results are now: > > > simple2(xdata=x,ydata=y) > [[1]] > > Call: > lm(formula = as.matrix(ydata) ~ as.matrix(xdata)) > > Coefficients: > (Intercept) as.matrix(xdata)x1 as.matrix(xdata)x2 > -6 21 -5 > > i've tried converting xdata and ydata to data frames but i still get > errors. > > simple3<-function(xdata,ydata) > { > xdata<-as.data.frame(xdata) > ydata<-as.data.frame(ydata) > ofit<-lm(ydata~xdata) > list(ofit) > } > > i.e. > > > simple3(xdata=x,ydata=y) > Error in model.frame(formula, rownames, variables, varnames, extras, > extranames, : > invalid variable type > > please help! > > thanking you in advance > > *** > allan
Hi, All, I use RGtk and Rtcltk to build some graphical interface for bioinformatics data analysis applications. I'm just wondering why the graphic display is so slow. For example, I tried to build a 2000 rows & 5 levels tree with both Rgtk and Rtcltk. RGtk cost about 15 seconds and Rtcltk about 10 seconds to load up... Is there a fatser way to build such application? I have difficulty install RJava in my machine, is RJava faster in building the tree representation? BTW, I'm using ibook G4 MacOS 10.3, R2.0 Many thanks. ___________________________________________________ Zhesi He Computational Biology Laboratory, University of York York YO10 5YW, U.K. Phone: +44-(0)1904-328279 Email: zh107 at york.ac.uk