[R] What's wrong with my code? (Edited version-added my data)

Susie susiecrab_ling at hotmail.com
Wed Jul 13 03:12:22 CEST 2011


Hey Josh,

Thank you so much for the help!

Now I have edited my codes--breaking into smaller pieces:)  R does not state
the error again:) 

However, the problem comes, please see my codes below-- You've suggested
earlier that I should move the "eight" part outside the loop;  I changed the
"eight" into "temp.dat", because I wanted the codes and functions to work on
every file. In order to include it into the loop, I renamed it into this
general name "temp.dat". 

The codes work--in the way that they generates plots and csv files-- BUT,
they somehow produce exactly the same plots and csv files (for the
number/length of my.files). 

I think the problem has to do with the way I named the files,
i.e."temp.dat". Is it wrong to name it like that? How should I name it so
that R produces the result desired? I also tried naming them "i", but it
doesn't work.

I believe it's just one last small step towards success, but I couldn't
figure it out. Please help me:) Thanks a lot in advance!!



my.files <- list.files()
for (i in 1: length(my.files)) {
temp.dat <- read.csv(my.files[i], header=TRUE, sep=",")}

for (i in 1: length(my.files)){
temp.datout <- subset(temp.dat, inout=="Outgoing from panel hh" &
o_duration>0, select=c(inout, enc_callee, o_duration))
}

for (i in 1: length(my.files)){
f <- function(temp.datoutf) nrow(temp.datoutf)
temp.datnocalls <- ddply(temp.datout,.(enc_callee),f)
colnames(temp.datnocalls)[2] <- "nocalls"
temp.datout$nocalls <- temp.datnocalls$nocalls
[match(temp.datout$enc_callee, temp.datnocalls$enc_callee)]
temp.datout=data.frame(temp.datout,"time"=c(1:nrow(temp.datout)))
}


for (i in 1: length(my.files)){
png(paste(Sys.Date(),"_",my.files[i],"_.png", sep=""))
plot(temp.datout$time, temp.datout$nocalls, main=my.files[i])
dev.off() 
write.csv(temp.datout, paste(Sys.Date(),"_",my.files[i],"_.csv", sep=""),
row.names=FALSE)
}


--
View this message in context: http://r.789695.n4.nabble.com/What-s-wrong-with-my-code-Edited-version-added-my-data-tp3662910p3663933.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list