[R] shift by one column given rows in a dataframe

maxbre mbressan at arpa.veneto.it
Fri Jul 24 08:55:02 CEST 2015


hi

thank you all for the great replies, very useful indeed even if some of them
a bit too aggressive (which is never, ever a good approach in my very humble
opinion... but that's a matter of taste and style I do not want to discuss
here); sorry again for bothering someone with such a trivial and
ill-conceived question

finally, I'm posting here my solution as a reference to the problem so that
to close this long and winding thread; 

hoping this code might be somehow useful for someonelse, sometime,
somewhere...

## start code

v0<-c("a","xxx","c",rep("xxx",2))
v1<-c(1,"b",3,"d","e")
v2<-c(6,2,8,4,5)
v3<-c("xxx",7,"xxx",9,10)
 
df_start<-data.frame(v0,v1,v2,v3, stringsAsFactors = FALSE)

df_start

# set vector of rows to be shifted left
shIftLeft<-c(2,4,5)

# shift selected rows
df_start[shIftLeft,1:3]<-df_start[shIftLeft,2:4]

# final result
df_end<-df_start[,1:3]

df_end

## end code

thanks




--
View this message in context: http://r.789695.n4.nabble.com/shift-by-one-column-given-rows-in-a-dataframe-tp4710256p4710294.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list