1 year ago
#352966
VÍCTOR MANUEL PÉREZ ROSA
how can I replace dot for comma?
Im trying to replace the dot of a fiji output for comma of all .txt in a folder. My problem is that I am using gsub function which coerce my numerical values to chraracters so when I try to become those character to a numerical class the comma produce me a sort of NAs in my dataframe.
path<- readline(prompt="añade la ruta donde están los archivos:")
setwd(path)
out<- readline(prompt="añade la ruta donde quieres guardar los archivos:")
archi<- dir(path = path, pattern = "*.txt")
x<-1
i<-1
for ( x in length(archi)) {
r<-archi[x]
data1<-read.delim2(r)
encabezado<- colnames(data1)
df<- matrix(ncol = length(encabezado), nrow = length(data1$X))
colnames(df)<- encabezado
df<- as.data.frame(df)
for (i in 1:length(encabezado)) {
df[,i]<- gsub("\\.",",", data1[,i])
df[,i]<- as.numeric(as.character(df[,i])) ·#here is the problem
}
write_xlsx(df, paste(out,r,".xlsx"))
}
do exist any function to convert my dataframe to numerical class?
Thanks in advance.
r
dataframe
gsub
0 Answers
Your Answer