I have a dataframe x with the columns a & b. I want to have a new column c whichs value is a/b. I’ve been using
x = read.csv(<file>,header=TRUE)
f <- function(...){
x$c = x$a / x$b
}
x = apply(x,1,f)
This messes up the dataframe so I suppose this is totally wrong. How can I access the values of the row on which apply is called at a given moment?
You don’t need to use
apply. These operations work perfectly fine on vectors.Will work just fine on it’s own.
For more info check out
?'/'.