I have problems reading a file with more than one row to carry out mathematical calculations I have a a file of the form mu1 mu2 alpha beta Wsigma sigmaA b r 25 15 .05 .05 22 3 .3 .5 30 20 .1 .2 22 .3 .3 .5 I intend to read one row , carry out the calculations and then the next row with which I intend to do the same calculations. I do the following. p<-read.table(file="eingabe.csv", header=TRUE,sep=";") data.frame(as.numeric(mu1<-p$mu1),as.numeric(mu2<-p$mu2), as.numeric(alpha<-p$alpha),as.numeric(beta<-p$beta), as.numeric(Wsigma<-p$Wsigma),as.numeric(sigmaA<-p$sigmaA),as.numeric(b<-p$b),as.numeric(r<-p$r)) I intend to use the variables stored in the the data frame for my caculations. but each time I try I get the followingerror message. Error in uniroot(function(n) eval(p.body) - power, c(2, 1e+07)) : invalid function value in 'zeroin' In addition: Warning message: the condition has length > 1 and only the first element will be used in: if (f(lower, ...) * f(upper, ...) >= 0) stop("f() values at end points not of opposite sign") ...which I do not get when I use just one row. Thanks sylvie ========================Sylvie B. Forkusam Eppelheimer Str.52/A2-5-2 69115 Heidelberg, Germany Tel: (0049)-06221/346913 Mobile: 0179-6816276 ====================== __________________________________ Free Pop-Up Blocker - Get it now
Hi, On Thu, 20 Nov 2003, forkusam wrote:> to carry out mathematical calculations > > I have a a file of the form > mu1 mu2 alpha beta Wsigma sigmaA b r > 25 15 .05 .05 22 3 .3 .5 > 30 20 .1 .2 22 .3 .3 .5 > > I intend to read one row , carry out the calculations > and then the next row with which I intend to do the > same calculations. > I do the following. > p<-read.table(file="eingabe.csv", header=TRUE,sep=";") > > data.frame(as.numeric(mu1<-p$mu1),as.numeric(mu2<-p$mu2), > > as.numeric(alpha<-p$alpha),as.numeric(beta<-p$beta), > > as.numeric(Wsigma<-p$Wsigma),as.numeric(sigmaA<-p$sigmaA),as.numeric(b<-p$b),as.numeric(r<-p$r))Is there any particular reason why you want to do this data.frame() line? To me it seems redundant. Each column is already in numeric/vector form, I believe.> Error in uniroot(function(n) eval(p.body) - power, > c(2, 1e+07)) : > invalid function value in 'zeroin' > In addition: Warning message: > the condition has length > 1 and only the first > element will be used in: if (f(lower, ...) * f(upper, > ...) >= 0) stop("f() values at end points not of > opposite sign")What kind of mathematical calculations were you trying to do when you got this error message? As discussed off-list last night, since you want to operate on each row using the same operation, have you tried using apply()? -- Cheers, Kevin --------------------------------------------------------------- "Try not. Do, do! Or do not. There is no try" Jedi Master Yoda ---- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)
On Thu, Nov 20, 2003 at 10:21:49AM -0800, forkusam wrote:> I have problems reading a file with more than one row > to carry out mathematical calculations > > I have a a file of the form > mu1 mu2 alpha beta Wsigma sigmaA b r > 25 15 .05 .05 22 3 .3 .5 > 30 20 .1 .2 22 .3 .3 .5 > > I intend to read one row , carry out the calculations > and then the next row with which I intend to do the > same calculations.Although you can read the file line by line I guess you actually want to read the whole table and then perform your calculations on the resulting data frame.> I do the following. > p<-read.table(file="eingabe.csv", header=TRUE,sep=";")Your file is not separated by ';'! From what you show above I guess it's tab-separated - or maybe by variying numbers of spaces. Assuming tabs this will read the entire file: p <- read.table('eingabe.csv', header=T, sep='\t')> data.frame(as.numeric(mu1<-p$mu1),as.numeric(mu2<-p$mu2), > as.numeric(alpha<-p$alpha),as.numeric(beta<-p$beta), > as.numeric(Wsigma<-p$Wsigma),as.numeric(sigmaA<-p$sigmaA),as.numeric(b<-p$b),as.numeric(r<-p$r))I'm totally confused about this. First, p is already a data frame. Second, the columns are already of type numeric or int after correctly reading the file - so as.numeric is not needed here. You should probably read 'An Introduction to R', especially the section on lists and data frames and the one about reading data from files.> I intend to use the variables stored in the the data > frame for my caculations. but each time I try I get > the followingerror message. > > Error in uniroot(function(n) eval(p.body) - power, > c(2, 1e+07)) : > invalid function value in 'zeroin' > In addition: Warning message: > the condition has length > 1 and only the first > element will be used in: if (f(lower, ...) * f(upper, > ...) >= 0) stop("f() values at end points not of > opposite sign") > > ...which I do not get when I use just one row.Since you didn't say what calculation you were attempting I can't even guess, what is going on. Maybe you can tell us what the goal of all this is and what commands you were using ... cu Philipp -- Dr. Philipp Pagel Tel. +49-89-3187-3675 Institute for Bioinformatics / MIPS Fax. +49-89-3187-3585 GSF - National Research Center for Environment and Health Ingolstaedter Landstrasse 1 85764 Neuherberg, Germany