This is a test version of Biostars. For the public version, visit https://www.biostars.org.
limiting functions to some columns in r

I want to sqrt all columns of my df except the first one which has chr = names in rstudio When I code: df2 <- sqrt(df[,-1]) it removes the first column of the df and than does sqrt. I want to limit sqrt to do all columns but the first.

transformation r sqrt

1 answer

One option is to use lappy

df[,-1] <- lapply(df[,-1], sqrt)

Log in to answer this question.