An embedded and charset-unspecified text was scrubbed... Name: Air.txt URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20220921/fea9097c/attachment.txt>
This post was empty. Tim From: R-help <r-help-bounces at r-project.org> On Behalf Of javad bayat Sent: Wednesday, September 21, 2022 2:09 AM To: R-help at r-project.org Subject: [R] Write text file in Fortran format [[alternative HTML version deleted]]
Hello, The attached file ends with R-Help's end message. This is unrelated to computer languages, Fortran, R or other. And there is no such thing as a Fortran format. Can you please describe the problem you have? Rui Barradas ?s 07:09 de 21/09/2022, javad bayat escreveu:
Dear Javad, Perhaps you were looking to read the table in Air.txt (is this Fortran format?) into R? b <- readLines("Air.txt") # The text MIME attachment w/Mailman footer ... b <- b[1:(which(b=="")-1)] # Remove the odd Mailman footer (at end of df) idx <- max(grep("^\\*", b))+1 # Start of df after header uline header <- tolower(strsplit(gsub(" +", "_", gsub("\\*", "", b[idx-2])), "_")[[1]]) b <- read.table(text=b[-(1:idx)], header=F) colnames(b) <- header[header!=""] b <- b[,sapply(b, \(i) length(unique(i)))>1] # Remove constant cols str(b) 'data.frame': 31324 obs. of 6 variables: $ x : num 583500 584000 584500 585000 585500 ... $ y : num 3018700 3018700 3018700 3018700 3018700 ... $ average conc: num 32.8 33.1 33.4 33.5 33.6 ... $ zelev : num 0 0 0 0 0 0 0 0 0 0 ... $ zhill : num 0 0 0 0 0 0 0 0 0 0 ... $ date(conc) : int 16101706 16101706 16101706 16101706 16101706 ... Best, Rasmus
Background: there is a data file whose records, after a header, can be describedby the Fortran format given in the header. YES, you can easily read that file in R, and you don't even need to know anything about Fortran formats to do it. You can read the file as a data frame using read.table using the skip=8 parameter to skip the header and the colnames=c("x", "y", ...) parameter to supply the column names. You will need to supply the column names yourself because one of the column names given has a space in it. On Wed, 21 Sept 2022 at 20:29, javad bayat <j.bayat194 at gmail.com> wrote:>[[alternative HTML version deleted]]