vendredi 19 août 2016

Conditional if loop for array multiplication - R

I am trying to multiply an array by a certain value. The array contains dates, and thus I would like to exclude them. I would like to use an if loop. I know there are other ways.

Data:

Date <- c("2014-12-18","2015-01-16", "2015-01-30")
W1 <- c("456", "468", "789") 
W2 <- c("456", "468", "789")
W3 <- c("456", "468", "789") 
df <- data.frame(Date, W1,W2,W3)
df$Date <- as.Date(df$Date, format="%Y-%m-%d")

Current if loop which is not working:

if(names(df) != "Date"){
  df_m <- df*0.0254
}

It is selecting the names of the columns I want, and I think it's multipling those rather than the data itself.

Aucun commentaire:

Enregistrer un commentaire