Knowing how to articulate a question
Aug. 16th, 2013 07:00 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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:
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.:
and
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:
MWA HA HA HA!
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)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)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.