replace - replacing values from two columns in R -


i have data frame 24 columns , second , third column like

1  2230 1  2300 1  2330  1  2400 2  30 2  100 

this part of columns. column 2 has 48 ones 48 twos 48 threes , on way 365. column 3 half hour time , starts 30 100 130 200 , on way 2400. patterns of each column end above example, last 1 corresponds 2400. need go though each column , replace 2400 0 , last value associated 2400 value plus 1 end with

1  2230 1  2300 1  2330  2  0 2  30 2  100 

i can replace values single column don't know how 2 columns 1 column depends on another. tried use loop , if statement coulnd't make work.

it should simple - if data.frame (df) has columns day , time:

df[df$time==2400,]$day <- df[df$time==2400,]$day + 1  df[df$time==2400,]$time <- 0 

if you're willing learn use data.table package, easier:

df[time==2400, c("day", "time"):= list(day + 1, 0)] 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -