rebeccmeister: (Acromyrmex)
[personal profile] rebeccmeister
Edited: All it takes is a morose post for me to start figuring things out and solving my own problems. The final answer is below.

Here's something I'm stuck on today.

An undergraduate and I have been working on analyzing some cricket videos, where we took overhead footage of the crickets, and then processed the videos and analyzed them with BioTrack. The result, for each cricket, there is a directory named after the video and cricket - e.g., cricket 9-47 was in the second video collected on July 4, 2013, so there's a folder called:

20130704_2_9-47

Within the folder are 5 relevant files which I want to combine, and then I want to generate a plot, so for every cricket I need to go through the following steps in R:


id<-read.table("20130704_2_9-47/id.btf", header=FALSE)
timage<-read.table("20130704_2_9-47/timage.btf", header=FALSE)
timestamp<-read.table("20130704_2_9-47/timestamp_frames.btf", header=FALSE)
xpos<-read.table("20130704_2_9-47/ximage.btf", header=FALSE)
ypos<-read.table("20130704_2_9-47/yimage.btf", header=FALSE)

track9.47<-data.frame(id, timage, timestamp, xpos, ypos)
track9.47<-rename(track9.47, c("V1"="ID", "V1.1"="timage", "V1.2"="timestamp", "V1.3"="xpos", "V1.4"="ypos"))
head(track9.47)
which(track9.47$xpos==0)
ctrack9.47<-subset(track9.47, track9.47$xpos!=0)

posplot<-ggplot(ctrack9.47, aes(xpos, ypos, group=ID))+geom_point()+geom_path(alpha=0.2)+geom_text(aes(label=timestamp), hjust=0, vjust=0, alpha=0.2)
posplot
ggsave(filename="Cricket9.47.pdf", width=10, height=10)


But I don't want to have to type all of that out for 30 crickets. I can extract the names of the directories and put them into their own vector, and can chop up the names, but I don't know how to assign the new names to the steps in my code, i.e.:

id<-read.table("FOLDERNAME/id.btf", header=FALSE)

and

trackCRICKETNUMBER<-data.frame(id, timage, timestamp, xpos, ypos)


I know this will involve looping or something of the sort, but don't know how to even articulate my question correctly so as to ask it somewhere useful and get helpful answers. Frustrating.

Edited:
Here's what I've got now:


for (i in seq(dnames))
{
id<-read.table(paste(dnames[i],"/","id.btf", sep=""), header=FALSE)
timage<-read.table(paste(dnames[i],"/","timage.btf", sep=""), header=FALSE)
timestamp<-read.table(paste(dnames[i],"/","timestamp_frames.btf", sep=""), header=FALSE)
xpos<-read.table(paste(dnames[i],"/","ximage.btf", sep=""), header=FALSE)
ypos<-read.table(paste(dnames[i],"/","yimage.btf",sep=""), header=FALSE)

blob<-data.frame(id, timage, timestamp, xpos, ypos)
blob<-rename(blob, c("V1"="ID", "V1.1"="timage", "V1.2"="timestamp", "V1.3"="xpos", "V1.4"="ypos"))
blobs<-subset(blob, blob$xpos!=0)

posplot<-ggplot(blobs, aes(xpos, ypos, group=ID))+geom_point()+geom_path(alpha=0.2)+geom_text(aes(label=timestamp), hjust=0, vjust=0, alpha=0.2)
posplot
ggsave(filename=paste("Cricket",cricks[i,6],".pdf", sep=""), width=10, height=10)

}


MWA HA HA HA!

getting answers to programming questions

Date: 2013-08-17 12:46 am (UTC)
From: (Anonymous)
You might try submitting a question at stackoverflow

http://stackoverflow.com/questions/tagged/r

I find the experts who hang out there often provide helpful answers to C++ questions.

Love,
Dad

Re: getting answers to programming questions

Date: 2013-08-17 02:31 pm (UTC)
From: [identity profile] rebeccmeister.livejournal.com
The part I struggle with is appropriate language use - I don't know when something is "iterative" or best completed as a loop or whether to call things directories or subdirectories. I'm sure it's not particularly important, but part of why I had a hard time tracking down answers in this particular case was because I just couldn't think of the right terminology to use to search out answers.

On the flipside, that might mean it's a useful question to pose so that other people who are as confused as me have a better chance of tracking down answers.

Profile

rebeccmeister: (Default)
rebeccmeister

June 2025

S M T W T F S
1 2 3 45 67
8 910 111213 14
151617 18 1920 21
22 2324 25262728
2930     

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 27th, 2025 03:56 am
Powered by Dreamwidth Studios