You need to read the documentation for read.xlsx and data.frame. In it you would discover what you have done wrong:
1. rowIndex must be an array listing the columns you wish to read not a character value 2. colIndex must be an array listing the rows you wish to read [Deleting these arguments will read all rows/columns which is probably what you want] 3. colClasses="character" are you trying to read these numbers as characters? Fortunately read.xlsx is ignoring your request since the correct value would be "char". Just delete this argument as well. 4. row.names gets passed to data.frame. It is looking for a number or character string indicating which column to use as rownumbers. Since you put TRUE, that gets converted to 1 and your first variable becomes the rowname. Certainly this is not what you want. Delete this argument as well. I think you will find this accomplishes what you want read<-read.xlsx("D:\\FYP\\image\\Cropped Images\\user227\\user227forger.xlsx", sheetName="Sheet1") ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Nurdiyanah Jambari > Sent: Tuesday, May 22, 2012 7:19 PM > To: Gabor Grothendieck > Cc: r-help@r-project.org > Subject: Re: [R] write.xls > > Hi can you please help me with this. Ive come up with this code to read > my > file, but receive an error that I ve no idea how to fix. > > > read<-read.xlsx("D:\\FYP\\image\\Cropped > Images\\user227\\user227forger.xlsx", sheetName="Sheet1", rowIndex="1", > colIndex="varLH2y", colClasses="character", row.names=TRUE) > >Error in colIndex - 1 : non-numeric argument to binary operator > > here is an example of my data in .xlsx (I have 20 rows of data in this > .xlsx) > > varLH2x varLH2y varHH2x varHH2y > varLL2x varLL2y varHL2x varHL2y > 1 4967.552716 12278.95794 679.3101705 254.2841431 4480777.986 > 3792655.605 > 2149.541058 827.9458738 > 2 5629.682598 8439.341331 812.4770397 326.7078909 6257926.174 > 4259659.878 > 1959.730324 1396.045697 > 3 5358.412977 8522.830297 967.7044858 420.9888243 6189762.401 > 3684682.244 > 3483.700887 1293.746943 > > -- > Nurdiyanah Bt Hj Jambari > Student > Faculty of Engineering > Bachelor Engineering of Computer & Communication System Engineering > University Putra Malaysia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.