Hi, i' d like to use R for simple calculations. I show you an examples to make clear my help request I' ve a file .csv like this (my real file is composed by 10.000 lines and 8 columns) x y 3 4 1 7 I' ve imported in R correctly. Now i want create a new variable named "t" and t is defined throught this relation: t = 4 (second element on x column) * 4 (first element on y column) in what way can i calculate t and print its value on an external file or, better, append t values as a column on my original csv??? Thanks Emanuele [[alternative HTML version deleted]]
you could use a loop but maybe easier would be x<-c(NA,x) y<-c(y,NA) t<-x*y use write.table() to write the table to your hard drive e.g. write.table(t, file="C:/Documents and Settings/simonp/My Documents/RELU/GIS data/Land Cover Map working/squares plus adjoining parcels/Scotland/scotland adj squares.csv", sep = ",",row.names = F) HTH, Si. ----- Original Message ----- From: "Carletto Rossi" <nuovodna at gmail.com> To: <r-help at r-project.org> Sent: Tuesday, June 02, 2009 11:22 AM Subject: [R] newbie help: simple operations in R> Hi, i' d like to use R for simple calculations. I show you an examples to > make clear my help request > > I' ve a file .csv like this (my real file is composed by 10.000 lines and > 8 > columns) > > x y > 3 4 > 1 7 > > I' ve imported in R correctly. Now i want create a new variable named "t" > and t is defined throught this relation: > > t = 4 (second element on x column) * 4 (first element on y column) > > in what way can i calculate t and print its value on an external file or, > better, append t values as a column on my original csv??? > > Thanks > > Emanuele > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
Hi r-help-bounces at r-project.org napsal dne 02.06.2009 12:22:49:> Hi, i' d like to use R for simple calculations. I show you an examplesto> make clear my help request > > I' ve a file .csv like this (my real file is composed by 10.000 linesand 8> columns) > > x y > 3 4 > 1 7 > > I' ve imported in R correctly. Now i want create a new variable named"t"> and t is defined throught this relation: > > t = 4 (second element on x column) * 4 (first element on y column) > > in what way can i calculate t and print its value on an external fileor,> better, append t values as a column on my original csv???It is rather difficult to evaluate what you really want to do. You say you have 10000 rows and 8 columns and your small example has only 2 columns and 2 rows. Do you want to use third and subsequent row, or third and further columns? If yes how? If you want to multiply second with first and third with second and ... than DF <- data.frame(x=c(5,3,7), y=c(1,4,2)) drop the first item from x and last item from y and multiply DF[-1,1]*DF[-3,2] Regards Petr> > Thanks > > Emanuele > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Reasonably Related Threads
- Difference beetwen element in the same column
- reading an image and adding a legend
- help using zeroinfl()
- [LLVMdev] Please benchmark new x86 vector shuffle lowering, planning to make it the default very soon!
- Non-monotonic spline using splinefun(method = "monoH.FC")