Re: [R] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear all; Many thanks for your useful comments and codes. I tried both Rui's and Jim's codes. Jim's codes gave an error as below: "Error in substr(inputline, 1, begincol3 - 1) : object 'inputline' not found" I don't know what's wrong. The Rui's codes worked correctly for the attached file. But I

Re: [R] Need help plotting

2022-09-21 Thread Rui Barradas
Hello, This type of problems generally has to do with reshaping the data. The format should be the long format and the data is in wide format. Inline. Às 23:35 de 21/09/2022, DFP escreveu: As I said, the lines below that you provided worked well for me. Can you explain what this line does?:

Re: [R] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear all; I apologise, I didn't know that I have to cc the list. Thank you Mr Rui for reminding me. Let me clarify more. I have no knowledge of the FORTRAN language. The text file that has been attached is a model's output file and I know that the format is in FORTRAN. I want to write a text file e

Re: [R] Need help plotting

2022-09-21 Thread Ebert,Timothy Aaron
Yes, but if you want to learn R (or relearn R) it would be better for you to decompress the code. You know what b looks like so add the next step. If you want to be able to see the original then save the output to another data frame. New_df <- b %>% mutate(Dtime = paste(Sys.Date(), Dtime),

Re: [R] Write text file in Fortran format

2022-09-21 Thread Richard O'Keefe
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

Re: [R] Write text file in Fortran format

2022-09-21 Thread Jim Lemon
Sorry, line 9 should be: if(substr(air[airline],1,1) == " ") Jim On Thu, Sep 22, 2022 at 8:51 AM Jim Lemon wrote: > > Hi Javad, > The example text file you sent doesn't appear to have the two > "trailer" lines that you describe. I would try this brute force method > as all you seem to want is t

Re: [R] Write text file in Fortran format

2022-09-21 Thread Jim Lemon
Hi Javad, The example text file you sent doesn't appear to have the two "trailer" lines that you describe. I would try this brute force method as all you seem to want is to multiply the third column values by a constant: air<-readLines("Air.txt") # define the column 3 field begincol3<-29 endcol3<-

Re: [R] Need help plotting

2022-09-21 Thread DFP
As I said, the lines below that you provided worked well for me. Can you explain what this line does?: # reshape to long format    pivot_longer(-Dtime, names_to = "NO2") %>% - library(ggplot2) library(dplyr) library(tidyr) b %>%    mutate(Dtime

[R] Need help plotting

2022-09-21 Thread DFP
Thank you for the ideas below.  That did work.  I thought I had tried "10 mins" before, but maybe I used just 10 min. === Yes, you can have date_breaks = "n mins" where n is any integer. date_breaks = "15 mins" date_breaks = "30 mins" date_breaks = "1 hour"   # or "1 hours", plural

Re: [R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Rui Barradas
Hello, In my previous I forgot that this, for matrices to have 2 classes , is relatively new. It was introduced in R 4.0.0. From the News file [1], point 2: R News [R logo] CHANGES IN 4.0.0 SIGNIFICANT USER-VISIBLE CHANGES matrix objects now also inherit from class "array", so e.g., class(

Re: [R] S4 dispatch ambiguity

2022-09-21 Thread Andrew Simmons
In the first scenario, your object is class AB, then class A with distance 1, then class B with distance 2. This means that method A is preferable since it is less distance away than method B. However, in your second function, both methods are a total distance of 3 away, so (as far as I know) it c

Re: [R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Rui Barradas
Hello, Check what class(datmat) returns and use ?inherits instead. class(datmat) #[1] "matrix" "array" inherits(datmat, "matrix") #[1] TRUE Also, the error the posted code gives is centrality(datmat,type="flow",center=TRUE) Error in checkDataTypes(y = NULL, networks = networks, lag = lag) :

Re: [R] How to set default encoding for sourced files

2022-09-21 Thread Andrew Simmons
If you're running it from Rscript, you'll have to specify the encoding like this: Rscript --encoding UTF-8 file If you're using R for Windows, I'm surprised this issue would come up since R 4.2.0 added support for UTF-8. At least on my own Windows machine, I can run exactly what you wrote and not

Re: [R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Andrew Simmons
In general, you should be using inherits(netwotks, "matrix") or is(networks, "matrix") instead of class() == Your function fails because your object has multiple classes so class== returns multiple logical values so if will fail. But inherits or is will return one logical value, so if will not ra

Re: [R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Eric Berger
In R 4.2.0 there is a significant change. When you use an if() statement with a condition of length > 1 this now reports an error. e.g. this link mentions it as a change https://www.jumpingrivers.com/blog/new-features-r420/ In your case this is because class(obj) can return a character vector of l

[R] Error in if (class(networks) == "matrix") from a function

2022-09-21 Thread Chao Liu
Dear R-Help community, This is a crosspost on SO but I've had no luck so far. So I have a function which computes a centrality index for the nodes in a network or matrix. Here is the function: library(igraph) #load package igraph centrality <- function (networks, type = c("indegree", "outdegree",

Re: [R] Write text file in Fortran format

2022-09-21 Thread Avi Gross
Javad, It would help if you stopped calling it FORTRAN format. I doubt anyone cares about names as compared to what kind of structure it holds. It likely is some variant on a file commonly used in R such as one that uses tabs or whitespace. It may have lines above with headers or comments and you

Re: [R] How to set default encoding for sourced files

2022-09-21 Thread Andrew Hart via R-help
On 21/09/2022 11:46, Bert Gunter wrote: ?options options(encoding = "utf-8") in a startup file or function should presumably do it. See ?Startup Bert Thanks everyone. Setting encoding in options in Rprofile.site has taken care of it. Curiously, it doesn't seem to solve the whole problem fo

Re: [R] Write text file in Fortran format

2022-09-21 Thread Rui Barradas
Hello, You forgot to cc the list. Here is a solution, I believe the comments explain the several steps. It's a matter to read in the file, separate the table from the rest, update the 3rd column, assemble the pieces back together and write to file. # this path depends on the OP's system path

Re: [R] Write text file in Fortran format

2022-09-21 Thread javad bayat
Dear Rasmus; I have no knowledge of the FORTRAN language. The text file that has been attached is a model's output file and I know that the format is in FORTRAN. I want to write a text file exactly similar to the attached text file using R programming. The steps below explain my goal: 1- Read the t

[R] S4 dispatch ambiguity

2022-09-21 Thread Xiongtao Dai
I am trying to make sense why the following does *not* result in ambiguous method selection and thus a warning: > setClass("A", slots=c(a  = "numeric")) > setClass("B", slots=c(b  = "numeric")) > setClass("AB", contains=c("A", "B")) > setGeneric("myg", function(object) standardGeneric("myg")) [1

Re: [R] How to set default encoding for sourced files

2022-09-21 Thread Bert Gunter
?options options(encoding = "utf-8") in a startup file or function should presumably do it. See ?Startup Bert On Wed, Sep 21, 2022 at 7:34 AM Andrew Hart via R-help wrote: > Hi there. I'm working with some utf-8 incoded csv files which gives me > data frames with utf-8 encoded headers. This me

Re: [R] How to set default encoding for sourced files

2022-09-21 Thread Eric Berger
Hi Andrew, If you look at ?source you see its default value for encoding is picked up from getOption("encoding"). Couldn't you just set this option in your Rprofile? HTH, Eric On Wed, Sep 21, 2022 at 5:34 PM Andrew Hart via R-help wrote: > > Hi there. I'm working with some utf-8 incoded csv fil

[R] How to set default encoding for sourced files

2022-09-21 Thread Andrew Hart via R-help
Hi there. I'm working with some utf-8 incoded csv files which gives me data frames with utf-8 encoded headers. This means when I write things like dat$proporción in an R script and then source it, I have to make sure the R script is incoded using utf-8 (and not latin1) and then I also have to ex

Re: [R] Write text file in Fortran format

2022-09-21 Thread Rasmus Liland
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("^

Re: [R] Write text file in Fortran format

2022-09-21 Thread Rui Barradas
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: __

Re: [R] Write text file in Fortran format

2022-09-21 Thread Jim Lemon
Hi, There was a .txt attachment that is some type of data file. Maybe what you mean is can the header be stripped and the rest written out in a format that can be input with a FORTRAN read routine. Yes, you just have to read it into a data frame and write it out so that it is in either free or fixe

Re: [R] Write text file in Fortran format

2022-09-21 Thread Ebert,Timothy Aaron
This post was empty. Tim From: R-help On Behalf Of javad bayat Sent: Wednesday, September 21, 2022 2:09 AM To: R-help@r-project.org Subject: [R] Write text file in Fortran format [[alternative HTML version deleted]] __ R-help@r-project.org

Re: [R] aplpack / bagplot

2022-09-21 Thread Eric Berger
[re-sending as plain text] Hi Sigbert, I have never used the aplpack package but out of curiosity I tried it out. Doing a scatter plot of your (x,y) data shows that there are many repeated x values, and this seems to be the source of the error. There are no repeated y values. It seems that the bag

Re: [R] aplpack / bagplot

2022-09-21 Thread Eric Berger
Hi Sigbert, I have never used the aplpack package but out of curiosity I tried it out. Doing a scatter plot of your (x,y) data shows that there are many repeated x values, and this seems to be the source of the error. There are no repeated y values. It seems that the bagplot() function does not han

[R] aplpack / bagplot

2022-09-21 Thread Sigbert Klinke
Hi, I get an error when I use bagplot from the package aplpack. Any ideas what theproblem is with the data set? library("aplpack") x <- c(5, 2, 1, 6, 3, 5, 4, 7, 4, 4, 3, 4, 5, 4, 6, 3, 3) y <- c(2, 3, 4, 6, 7, 8, 10, 11, 12, 13, 1, 14, 17, 18, 19, 20, 22) bagplot(y,x) # works bagplot(x,y)