[R] defining a function by branches
Hi there, How can I plot a function in R which is defined by conditional branches?, e.g.: u(x) = 1, Edx2Ed (where Ed is a positive constant, say, 25); u(x)=0.5*x, x2Ed curve(u(x), ) So far I have had to use curve(..., add=TRUE) with two function define by segments, i.e., two branches or intervals for the variable x, say, 25,50 and then from 50,... and I would appreciate a more elegant solution if possible. Thanks a lot, Pedro Rodrigues de Almeida Helsinki - Finland __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
This is a strange result. I couldn't have a similar result, even with your exact call to read.table. Maybe there is a problem with the file (possibly some white space characters not cleaned). If you send the first 5 lines of your text file I could say something more. On Mon, 2004-07-19 at 09:05, Vincent MUTEAUD wrote: Hello R-users, I apologize for my question but I'm a newbie. I want to read a file which columns separator is \t. At the end of each row there is a \n to go to the following line. The three first lines are remarks lines and the fourth contains columns titles ( variables names, ids, dates, calculated values, observed values...) . I do: read.table(myFile, header=TRUE, sep = \t, skip = 3) I obtain a strange result, lines are in a bad order: cell6/voxel15 1998/365a 2.0 1.0 0.55 0.2748257492065 0\nRendement de la culture 0.0 crop4 0/0a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/75a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/150a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/225a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/300a 0.0 1.0 0.0 3.0368848 0\nRayonnement diffu reçu 0.0 crop1 0/0a0.0 2.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop1 1998/50a0.0 2.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop1 1998/100a 0.0 2.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop1 1998/150a 0.0 2.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop1 1998/200a 0.0 2.0 0.0 13.691006 0\nRayonnement diffu reçu 0.0 crop1 1998/250a 0.0 2.0 0.0 10.997387 0\nRayonnement diffu reçu 0.0 crop1 1998/300a 0.0 2.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop1 1998/350a 0.0 2.0 0.0 4.198115 0\nRayonnement diffu reçu 0.0 crop9 0/0a2.0 0.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop9 1998/50a2.0 0.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop9 1998/100a 2.0 0.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop9 1998/150a 2.0 0.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop9 1998/200a 2.0 0.0 0.0 13.676454 0\nRayonnement diffu reçu 0.0 crop9 1998/250a 2.0 0.0 0.0 10.983188 0\nRayonnement diffu reçu 0.0 crop9 1998/300a 2.0 0.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop9 1998/350a 2.0 0.0 0.0 4.198115 0\n weightingid date x yz calculated observed 1 0 tree1 1998/365a 1.5 1.5 0.00 1.58e+02 162.000 2 0 tree1 0/0a 1.5 1.5 0.00 6.242254e-030.007 3 0 tree1 1998/365a 1.5 1.5 0.00 1.038187e-020.011 4 0 tree1 1998/365a 1.5 1.5 0.00 1.008111e+000.000 5 0 cell4/voxel23 1998/365a 0.0 1.0 0.55 0.00e+000.000 6 0 cell5/voxel18 1998/365a 1.0 1.0 0.25 0.00e+000.000 7 0 cell5/voxel20 1998/365a 1.0 1.0 0.90 0.00e+000.000 8 0 cell6/voxel15 1998/365a 2.0 1.0 0.55 0.00e+000.000 9NA NA NA NA NA NA The \n is read like a word and not like a symbol to skip a line. What should I do? Thanks __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
The email has changed the file. Please send attached. On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
The option quote states the character that encloses strings in your file. for instance if you had a file with Name Height Tree1 100.3 you should call read.table with quote=\. On Mon, 2004-07-19 at 10:25, Vincent MUTEAUD wrote: That's allright, thanks a lot. What is the signification of quote exactly? A 10:08 19/07/2004 +0100, Pedro Rodrigues a écrit : If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] stl,package=stats
On Sun, 2004-07-18 at 18:38, bob mccall wrote: Greetings: I'm using the time series decomposition routine stl from the package stats. But how do I get the results into a vector to work with them? example: data(AirPassengers) m-stl(AirPassengers,per) print(m) This lists the output but can't figure out how to extract the individual series like seasonal, trend, irregular. # Seasonal as.vector(m$time.series[,1]) # Trend as.vector(m$time.series[,2]) # Remainder as.vector(m$time.series[,3]) Thanks, Bob - Vote for the stars of Yahoo!'s next ad campaign! [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] (kein Betreff)
On Wed, 2004-03-31 at 19:01, Mag. Ferri Leberl wrote: Dear colleagues! How can I calculate the mean of every line of feld without using the command for? Thank You in advance feld-array(,c(100,10)) mittel-array(,c(100,1)) feld[,]-rnorm(1000) for(a in 1:100){mittel[a]-mean(feld[a,])} You could use: mittel - apply(feld, 1, mean) prodrigues __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] How to save images?
Maybe you could just PrintScreen or use the pdf() function which uses one or several pdf files instead of the default graphical device. After I use function plot() to get an image, how can I save the image or export it to .gif or other digital formats? Thanks a lot. -- --- Pedro Pereira Rodrigues http://www.dcc.fc.up.pt/~prodrigues/ Artificial Intelligence and Data Analysis Group Artificial Intelligence and Computer Science Laboratory (+351)226078830 - Ext: 121 University of Porto __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] nnet problem
I believe you want to fit a nnet model to predict numeric data. you can try as follows: xx - Matrix of size INPUTS*EXAMPLESTRAIN yy - Vector of size EXAMPLESTRAIN x1 - Matrix of size INPUTS*EXAMPLESTEST # fit your model like this nnetmodel - nnet(x=xx, y=yy, ) # or like this only if dealing with a data.frame nnetmodel - nnet(outname ~ in1name + ... inNname, ) # here numdata will become a vector of size EXAMPLESTEST. numdata - predict(nnetmodel, x1) Best Regards Pedro On Fri, 2004-02-06 at 14:36, [EMAIL PROTECTED] wrote: Hello everybody, I want to use the nnet library and my problem is that the algorithm seems to accept only class as target when the neural is fiiting. So the output when I use predict.nnet is also a class. Is it possible to have numeric variable as target ? If yes, what is the syntax ? Thank you. Cordialement, Rgis CHARIGNON ** Attention : le present message et toutes les pieces jointes (le message) sont confidentiels et etablis a l'attention exclusive du ou des destinataire(s) indique(s). Toute autre diffusion ou utilisation non autorisee est interdite. Si vous recevez ce message par erreur, veuillez immediatement en avertir l'expediteur par e-mail en retour, detruire le message et vous abstenir de toute reference aux informations qui y figurent afin d'eviter les sanctions attachees a la divulgation et a l'utilisation d'informations confidentielles. Les messages electroniques sont susceptibles d'alteration. Lagardere SCA et ses filiales declinent toute responsabilite en cas d'alteration ou de falsification du present message. Warning : this e-mail and any files attached (the e-mail) are confidential and intended solely to the named addressee(s). Any unauthorised dissemination or use is strictly prohibited. If you received this e-mail in error, please immediately notify the sender by reply e-mail and then delete the e-mail from your system. Please do not copy, use or make reference to it for any purpose, or disclose its contents to any person : to do so could expose you to sanctions. E-mails can be altered or falsified. Lagardere SCA and its subsidiary companies shall not be liable for any alteration or falsification on this e-mail. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] for loops?
On Mon, 2004-02-02 at 13:42, Catherine Stein wrote: Hello R people! How can one use a for loop (or something similar) in R? As I type in each line, I get syntax errors... I'm just confused how much to type in at each prompt. Thanks for your help, cathy Hello. I believe you want something like: for(i in 1:n){ ...some lines here... } If you have only one line within the for loop you can use it without the brackets. If the environment is still open (as within the for loop) you will not get a new prompt but a + prompt to continue as if you were writing on the same line. Only when you close the brackets the prompt will return to after executing the for loop. Hope this will help. Pedro -- --- Pedro Pereira Rodrigues http://www.dcc.fc.up.pt/~prodrigues/ Phone: +351 226078830 - Ext: 121 Snail: Department of Computer Science Faculty of Sciences - University of Porto Rua do Campo Alegre, 823 4150-180 Porto - Portugal __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html