[R] Write text file in Fortran format

Rasmus Liland jr@| @end|ng |rom po@teo@no
Wed Sep 21 15:48:57 CEST 2022


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



More information about the R-help mailing list