# Get all the files ending with .heights
filelist <- list.files(pattern = "\\.heights")
# Get all the data. Put into a single data.frame
# Assuming that you don't have thousands of
# files/measurements, rbind()ing shouldn't be too slow.
df <- data.frame(person = character(),
dates = character(),
height = numeric())
# Iterate through, collecting the data into a data.frame
for (fname in filelist){
x <- read.table(fname, sep="", as.is = TRUE)
person <- gsub("\\.heights", "", fname)
names(x) <- c("dates", "height")
df <- rbind(df, data.frame(person = rep(person, times = nrow(x)),
dates = x$dates,
height = x$height))
}
# Convert dates to POSIXct
df$dates <- strptime(as.character(df$dates), "%d/%m/%Y")
df$dates <- as.POSIXct(df$dates)
# Plot with qplot
require(ggplot2)
pdf("Heights.pdf")
qplot(dates, height, data = df, color = person)
dev.off()
# Plot with base graphics
pdf("Heights_2.pdf")
plot(df$dates, df$height, col = as.numeric(df$person))
dev.off()