Jericon
Jericon

Reputation: 5172

Comparing data from 2 files using R

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.

Upvotes: 0

Views: 4518

Answers (2)

Josh O'Brien
Josh O'Brien

Reputation: 162321

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)

Upvotes: 1

mathematical.coffee
mathematical.coffee

Reputation: 56915

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.

Upvotes: 3

Related Questions