jeudi 2 février 2017

Apply function to each element in dataframe using value with same index in another dataframe r

I want to apply a function to each element in a data frame using values from the same corresponding column in another data frame. For example:

B<- data.frame(seq(1:32), nrow=4, ncol=8)
A<- data.frame(seq(1:16), nrow=1, ncol=8)

B[,2]<- ifelse(B[,2]<A[,2], "0", B[,2])

I'd like to do this using apply() if possible.

I'm new to R and have tried extensively to find a solution. Any help would be much appreciated.

Aucun commentaire:

Enregistrer un commentaire