1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| library(here)
library(readr)
setwd(here(paste("data1", sep="",collapse = NULL)))
files <- list.files(here(paste("data1",sep="",collapse=NULL)))
nb_files <- length(files)
m <- data.frame(files)
b <- sapply(files, read.table, header=T, sep=",", dec=".")
b <- data.frame(b)
b <- t(b)
temp<-1
temp <- list(temp)
for(j in 1:nb_files){
b[[j]]$y[b[[j]]$y>=10]<-255
b[[j]]$tot <- c(TRUE, b[[j]]$y[-1]!=b[[j]]$y[-nrow(b[[j]])])*1
temp[[j]] <- subset(b[[j]], b[[j]]$tot==1)
temp[[j]]$V4 <-0
for(i in 1:nrow(temp[[j]])){
if(temp[[j]][i,2] == 255){
temp[[j]][i,4] <- temp[[j]][i+1,1]-temp[[j]][i,1]-1
}
else{}
}
}
for(j in 1:nb_files){
#temp[[j]]$x<-NULL
#temp[[j]]$y<-NULL
#temp[[j]]$tot<-NULL
temp[[j]] <- replace(temp[[j]],is.na(temp[[j]]),0)
temp[[j]] <- subset(temp[[j]], temp[[j]]$V4 != 0)
} |
Partager