0

I have 2 files that contain benchmark results for the same test on 2 different hosts. The results are raw data in space separated format.

I need to be able to compare them to each other as the hosts are not the same. Primarily for the purposes of graphing. Is there a way to add a "field" or column that is unique to each file (but the same to all rows in that file), which I can then use to differentiate the results in a graph? How else could I go about doing this.

Jericon
  • 4,992
  • 3
  • 20
  • 22

2 Answers2

3

You can just explicitly add in the extra column.

For example:

# first file
df1 <- read.table(...)
 # identify as first file
df1$file_name <- 'file1'

# second file
df2 <- read.table(...)
df2$file_name <- 'file2'

# combine:
df <- rbind(df1,df2)

Of course you don't need to do it in so many steps, but this should give you a starting direction.

mathematical.coffee
  • 55,977
  • 11
  • 154
  • 194
  • This is throwing an error: "Error in match.names(clabs, names(xi)) : names do not match previous names" – Jericon Mar 08 '12 at 01:27
  • This is because your two data frames must have different column names -- your file 1 and file 2 have different column names. Set them to the same before merging (for example if `df1` has columns `a` and `c`, while `df2` has columns `a` and `b`, R won't combine `b` into the same column as `c` because they probably have different column names because they shouldn't be combined). – mathematical.coffee Mar 08 '12 at 01:35
  • They had the same column names. But I had defined the names of the columns after the rbind. Moving that before fixed it. Thanks! – Jericon Mar 08 '12 at 02:01
1

Here's the general idea:

# Some example data
d1 <- read.table(text = "
a b
1 2
2 8
3 4", header=T)

d2 <- read.table(text = "
a b
1 3
2 10
3 5", header=T)

# Add an identifying column to each data.frame, then 'rbind()' them together
d1 <- data.frame(host = "host1", d1)
d2 <- data.frame(host = "host2", d2)
d <- rbind(d1, d2)

# Plot the results with your graphical system of choice
library(lattice)
xyplot(b~a, group=host, data=d, type="b", auto.key=TRUE)
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455