[R] Odp: newbie help: simple operations in R
Petr PIKAL
petr.pikal at precheza.cz
Tue Jun 2 13:18:05 CEST 2009
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 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???
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 guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list