limiting functions to some columns in r
1
0
Entering edit mode
23 months ago

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 • 790 views
ADD COMMENT
3
Entering edit mode
23 months ago
barslmn ★ 2.3k

One option is to use lappy

df[,-1] <- lapply(df[,-1], sqrt)
ADD COMMENT
0
Entering edit mode

Great, thank you.

ADD REPLY

Login before adding your answer.

Traffic: 1514 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6