Operation for element in dataframe

Hi, community.

I meet an basic but interesting question when practicing R. How could we do the same operation on each element of the data frame, for example every element + 1? I know c5+1 or sapply function work. Is there any way?

What's more, how could we do different operation for element in different column or row? For example, first column(or row)+1, others not change. Or the element in odd number column(or row)+1, others-10.

Any help would be appreciated.


Maybe something like this for the alternating row issue?

xx  <- seq(1, 19, by = 2)
c5[xx, 1 ]  <- c5[xx, 1] + 1
1 Like

Thank you for your help.
Would you mind to show your opinion more specifically according to original post question?

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.