I am trying to increase the value of all the numbers in a table similar to the one below. Is there any way to do this in R? I am aware this is a very simple task in python.
if(!require(tidyverse)){install.packages("tidyverse");library('tidyverse')}
Gene = sprintf("Gene_%s", rep(10:39))
Cell = sprintf("Cell_%s", rep(10:19))
mat <- matrix(rnorm(10), ncol = 10, nrow = 30)
df <- as.data.frame(mat)
colnames(df) <- Cell
row.names(df) <- Gene
df <- rownames_to_column(df,var = "Gene")
df
I have tried df + 1 and get an error:
Error in FUN(left, right): non-numeric argument to binary operator
Traceback:
1. Ops.data.frame(df, 1)
2. eval(f)
3. eval(f)
My desired output is something like this...
example <- df$Cell_10 + 1
example
However I need to do this for the whole dataframe