cbinding 2 dataframes (equal number of rows) few columns having common names results in data.frame common names altered (e.g. namea.1, nameb.1, etc) avoid issues.
i noticed though names have changed, there data substitutions. specifically, resulting data.frame had data first data.frame in columns same name, in supposed have data second data.frame.
this 1 easy overcome, since 1 can change names prior cbind might sneak errors in results.
------edit---- i'll try provide example:
df1 is:
row seqnames start end width strand region extra1 1 chr10 8111 8111 172 * 123 456 2 chr11 8112 8112 173 * 123b 456b and df2 is:
row seqnames start end width strand whatever1 whatever2 1 chr12 9111 9111 174 + abc efg 2 chr13 9112 9112 175 + abcb efgb i perform cbind , get:
row seqnames start end width strand region extra1 seqnames.1 start.1 end.1 width.1 strand.1 whatever1 whatever2 1 chr10 8111 8111 172 * 123 456 chr10 8111 8111 172 * abc efg 2 chr11 8112 8112 173 * 123b 456b chr11 8112 8112 173 * abcb efgb the values in second part belong df1 instead of df2. happens in columns had same name in df1 , df2. have been automatically renamed data have been repeated first df.
question: normal behavior?
i hope helps
thank again
not sure question, can specify own column prefix columns of each merged object named arguments of cbind:
data('cars') cars2=cbind(dataset1=cars, dataset2=cars) head(cars2) # dataset1.speed dataset1.dist dataset2.speed dataset2.dist # 1 4 2 4 2 # 2 4 10 4 10 # 3 7 4 7 4 # 4 7 22 7 22 # 5 8 16 8 16 # 6 9 10 9 10
Comments
Post a Comment