Re: [R] Mathematical working procedure of imputation methods (medianImpute, knnImpute, and bagImpute) in caret package R

2022-09-20 Thread Richard O'Keefe
?preProcess
 k-nearest neighbor imputation is carried out by finding the k
 closest samples (Euclidian distance) in the training set.
 Imputation via bagging fits a bagged tree model for each predictor
 (as a function of all the others). This method is simple, accurate
 and accepts missing values, but it has much higher computational
 cost. Imputation via medians takes the median of each predictor in
 the training set, and uses them to fill missing values. This
 method is simple, fast, and accepts missing values, but treats
 each predictor independently, and may be inaccurate.
...
References:

 

 Kuhn and Johnson (2013), Applied Predictive Modeling, Springer,
 New York (chapter 4)

 Kuhn (2008), Building predictive models in R using the caret
 (doi:10.18637/jss.v028.i05
 )

There are more references, but you really should read Kuhn (2008).

It's not clear what kind of understanding you need.
How the methods work?  The description above TELLS you what they do.
How WELL the methods work?  Again the description above is pretty
clear.  It says such and such is fast and so and so "has much higher
computational cost", which is surely what you want to know for large
amounts of data?  How fast the methods will be on your machine with
your data can only be determined by benchmarking, and you do not
need the internals for that.

All of this is open source so you can easily find the internals for
yourself if you really want to.  If nothing else, it's at
https://github.com/topepo/caret



On Wed, 21 Sept 2022 at 09:20, K Purna Prakash 
wrote:

> Dear Sir/Madam,
> Greetings!!!
>
> Kindly provide the detailed internal mathematical working mechanism of the
> following median, KNN, and bagging imputation methods available in caret
> package R.
>
>  preProcess(train_data, method = "medianImpute")
>  preProcess(train_data, method = "knnnImpute")
>  preProcess(train_data method = "bagImpute")
>
> The details provided by you will help me a lot for a better understanding
> of these imputation methods especially while dealing with large sets of
> data.
>
> I will look forward to hearing from you.
>
> Thanks and regards,
> K. Purna Prakash.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Mathematical working procedure of imputation methods (medianImpute, knnImpute, and bagImpute) in caret package R

2022-09-20 Thread Bert Gunter
R is open source. Look at the code and read it.
Alternatively, look at references for all of this. e.g. on Wikipedia or via
web search. We generally do not provide statistical instruction on this
list.

Bert

On Tue, Sep 20, 2022 at 2:20 PM K Purna Prakash 
wrote:

> Dear Sir/Madam,
> Greetings!!!
>
> Kindly provide the detailed internal mathematical working mechanism of the
> following median, KNN, and bagging imputation methods available in caret
> package R.
>
>  preProcess(train_data, method = "medianImpute")
>  preProcess(train_data, method = "knnnImpute")
>  preProcess(train_data method = "bagImpute")
>
> The details provided by you will help me a lot for a better understanding
> of these imputation methods especially while dealing with large sets of
> data.
>
> I will look forward to hearing from you.
>
> Thanks and regards,
> K. Purna Prakash.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Mathematical working procedure of imputation methods (medianImpute, knnImpute, and bagImpute) in caret package R

2022-09-20 Thread K Purna Prakash
Dear Sir/Madam,
Greetings!!!

Kindly provide the detailed internal mathematical working mechanism of the
following median, KNN, and bagging imputation methods available in caret
package R.

 preProcess(train_data, method = "medianImpute")
 preProcess(train_data, method = "knnnImpute")
 preProcess(train_data method = "bagImpute")

The details provided by you will help me a lot for a better understanding
of these imputation methods especially while dealing with large sets of
data.

I will look forward to hearing from you.

Thanks and regards,
K. Purna Prakash.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need help plotting

2022-09-20 Thread Ebert,Timothy Aaron
Have you done something like this first?
install.packages("chron")

After that comes

library(chron)

and the rest of your code.

Tim
-Original Message-
From: R-help  On Behalf Of Bert Gunter
Sent: Tuesday, September 20, 2022 11:57 AM
To: Parkhurst, David 
Cc: r-help@r-project.org
Subject: Re: [R] Need help plotting

[External Email]

"Also, IU's tech support told me yesterday that if I responded to a message 
that came as plain text, my response would go out as plain text.  Is that true 
for this response, or is it in HTML?"

Nope, HTML. You need to set your email client to send in plain text. Do an 
internet search on how to do this, e.g. with "How to send plain text email for 
<>".

Also see "?download.packages" for how to get packages from an R package 
repository (though RStudio and no doubt other IDE's have an interface through 
which to do this).

Cheers,
Bert

On Tue, Sep 20, 2022 at 8:49 AM Parkhurst, David 
wrote:

> I like the looks of what you are doing here.
>
> However, this from my system:
> > library(chron)
> Error in library(chron) : there is no package called 'chron'
>
> How can I get chron?
>
> Also, IU's tech support told me yesterday that if I responded to a 
> message that came as plain text, my response would go out as plain 
> text.  Is that true for this response, or is it in HTML?
>
> From: Rui Barradas 
> Date: Tuesday, September 20, 2022 at 4:52 AM
> To: Jim Lemon , Parkhurst, David < 
> parkh...@indiana.edu>, r-help mailing list 
> Subject: Re: [R] Need help plotting
> Hello,
>
> Now with data, here are base R and ggplot2 plots.
>
>
> b <- read.table(text=
>  "Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2
> MVOCMpm10 Mpm2.5 Mpm1
>   18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00
>   21
>   18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00
>   21
>   18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00
>   21",
>header=TRUE,stringsAsFactors=FALSE)
>
>
> # This base R plot needs package chron
> library(chron)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat
> .ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl
> .edu%7C8fab207eca574151439308da9b2115b3%7C0d4da0f84a314d76ace60a62331e
> 1b84%7C0%7C0%7C637992863653204275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4w
> LjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C
> &sdata=aiBOxqQsZI1Mc1vF3tDW5skxG7dTAw2J0ZOCvnJdJFc%3D&reserved
> =0
> PLEASE do read the posting guide
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r
> -project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%
> 7C8fab207eca574151439308da9b2115b3%7C0d4da0f84a314d76ace60a62331e1b84%
> 7C0%7C0%7C637992863653204275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwM
> DAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&
> sdata=ujwOnmg30fp6NUKoTk17Uev0pg2LBf0i8qvUtM%2F%2Fjvk%3D&reserved=
> 0 and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C8fab207eca574151439308da9b2115b3%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637992863653204275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aiBOxqQsZI1Mc1vF3tDW5skxG7dTAw2J0ZOCvnJdJFc%3D&reserved=0
PLEASE do read the posting guide 
https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C8fab207eca574151439308da9b2115b3%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637992863653360508%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dFIosQzsmHgaofIKXLjVlEOcHUSlSpchBhyr%2BMMKJiU%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] getDividents() doesn't work

2022-09-20 Thread Ivan Krylov
On Mon, 19 Sep 2022 20:47:55 +
Phil Smith via R-help  wrote:

> incomplete final line found by readTableHeader on
> 'https://query1.finance.yahoo.com/v7/finance/download/VOX?period1=-2208988800&period2=1663545600&interval=1d&events=split'

When I follow the link myself, I get a CSV file that contains a single
header line and no data lines at all. Not sure whether it's Yahoo's
problem or quantmod's problem, but it's definitely related.

-- 
Best regards,
Ivan

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] getDividents() doesn't work

2022-09-20 Thread Bert Gunter
... and do note that a "warning" is not an "error." Often the correct
result will still be obtained.

-- Bert

On Tue, Sep 20, 2022 at 9:48 AM Phil Smith via R-help 
wrote:

> Hi R-Help People!
>
> I'm using the current version of R for Ubuntu: R version 4.2.1
> (2022-06-23) -- "Funny-Looking Kid."
>
> I'm using the quantmod package and am having difficulty with the
> getDividends() function from the quantmod package.
>
> Here is my code:
>
> > library(quantmod)
>
> >
> > getDividends( "VOX" )
>
> Here is the output:
> Warning message:
> In read.table(file = file, header = header, sep = sep, quote = quote, :
> incomplete final line found by readTableHeader on '
> https://query1.finance.yahoo.com/v7/finance/download/VOX?period1=-2208988800&period2=1663545600&interval=1d&events=split
> '>
>
> There was not an object in my work space like "VOC.div" or anything like
> that, so I'm pretty sure getDividends failed completely
>
>  except for the slight possiblity that I did something wrong!
>
> Can somebody please tell me how to get getDividends to work?
>
> Thank you!
> Daryl
> Daryl's Rural Roadside Honor System Vegetable and Flower Stand and
> Occasional Dairy Produce
> Rural area, USA
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] getDividents() doesn't work

2022-09-20 Thread Joshua Ulrich
You need to assign the result to an object.

vox_div <- quantmod::getDividends("VOX")

You should check to see if the dividends are split-adjusted or not.
Yahoo has changed that several times over the years. Use the
`split.adjust` argument to get the (un)adjusted dividends. The boolean
may be backward because of Yahoo's changes.

Best,
Josh

On Tue, Sep 20, 2022 at 11:48 AM Phil Smith via R-help
 wrote:
>
> Hi R-Help People!
>
> I'm using the current version of R for Ubuntu: R version 4.2.1 (2022-06-23) 
> -- "Funny-Looking Kid."
>
> I'm using the quantmod package and am having difficulty with the 
> getDividends() function from the quantmod package.
>
> Here is my code:
>
> > library(quantmod)
>
> >
> > getDividends( "VOX" )
>
> Here is the output:
> Warning message:
> In read.table(file = file, header = header, sep = sep, quote = quote, :
> incomplete final line found by readTableHeader on 
> 'https://query1.finance.yahoo.com/v7/finance/download/VOX?period1=-2208988800&period2=1663545600&interval=1d&events=split'>
>
> There was not an object in my work space like "VOC.div" or anything like 
> that, so I'm pretty sure getDividends failed completely
>
>  except for the slight possiblity that I did something wrong!
>
> Can somebody please tell me how to get getDividends to work?
>
> Thank you!
> Daryl
> Daryl's Rural Roadside Honor System Vegetable and Flower Stand and Occasional 
> Dairy Produce
> Rural area, USA
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] getDividents() doesn't work

2022-09-20 Thread Phil Smith via R-help
Hi R-Help People!

I'm using the current version of R for Ubuntu: R version 4.2.1 (2022-06-23) -- 
"Funny-Looking Kid."

I'm using the quantmod package and am having difficulty with the getDividends() 
function from the quantmod package.

Here is my code:

> library(quantmod)

>
> getDividends( "VOX" )

Here is the output:
Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 
'https://query1.finance.yahoo.com/v7/finance/download/VOX?period1=-2208988800&period2=1663545600&interval=1d&events=split'>

There was not an object in my work space like "VOC.div" or anything like that, 
so I'm pretty sure getDividends failed completely

 except for the slight possiblity that I did something wrong!

Can somebody please tell me how to get getDividends to work?

Thank you!
Daryl
Daryl's Rural Roadside Honor System Vegetable and Flower Stand and Occasional 
Dairy Produce
Rural area, USA
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need help plotting

2022-09-20 Thread Bert Gunter
"Also, IU’s tech support told me yesterday that if I responded to a message
that came as plain text, my response would go out as plain text.  Is that
true for this response, or is it in HTML?"

Nope, HTML. You need to set your email client to send in plain text. Do an
internet search on how to do this, e.g. with "How to send plain text email
for <>".

Also see "?download.packages" for how to get packages from an R package
repository (though RStudio and no doubt other IDE's have an interface
through which to do this).

Cheers,
Bert

On Tue, Sep 20, 2022 at 8:49 AM Parkhurst, David 
wrote:

> I like the looks of what you are doing here.
>
> However, this from my system:
> > library(chron)
> Error in library(chron) : there is no package called ‘chron’
>
> How can I get chron?
>
> Also, IU’s tech support told me yesterday that if I responded to a message
> that came as plain text, my response would go out as plain text.  Is that
> true for this response, or is it in HTML?
>
> From: Rui Barradas 
> Date: Tuesday, September 20, 2022 at 4:52 AM
> To: Jim Lemon , Parkhurst, David <
> parkh...@indiana.edu>, r-help mailing list 
> Subject: Re: [R] Need help plotting
> Hello,
>
> Now with data, here are base R and ggplot2 plots.
>
>
> b <- read.table(text=
>  "Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2
> MVOCMpm10 Mpm2.5 Mpm1
>   18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00
>   21
>   18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00
>   21
>   18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00
>   21",
>header=TRUE,stringsAsFactors=FALSE)
>
>
> # This base R plot needs package chron
> library(chron)
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need help plotting

2022-09-20 Thread Parkhurst, David
I like the looks of what you are doing here.

However, this from my system:
> library(chron)
Error in library(chron) : there is no package called �chron�

How can I get chron?

Also, IU�s tech support told me yesterday that if I responded to a message that 
came as plain text, my response would go out as plain text.  Is that true for 
this response, or is it in HTML?

From: Rui Barradas 
Date: Tuesday, September 20, 2022 at 4:52 AM
To: Jim Lemon , Parkhurst, David , 
r-help mailing list 
Subject: Re: [R] Need help plotting
Hello,

Now with data, here are base R and ggplot2 plots.


b <- read.table(text=
 "Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2
MVOCMpm10 Mpm2.5 Mpm1
  18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00
  21
  18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00
  21
  18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00
  21",
   header=TRUE,stringsAsFactors=FALSE)


# This base R plot needs package chron
library(chron)


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to find the variance-covariance matrix of a random-vector using R

2022-09-20 Thread Bill Dunlap
?var

E.g.,

> x <- mvtnorm::rmvnorm(1e5, mean=101:105, sigma=matrix(1,5,5)+diag(11:15))
> dim(x)
[1] 10  5
> var(x)
   [,1]   [,2]   [,3]   [,4]  [,5]
[1,] 11.9666055  1.0603876  0.9627672  1.0371084  0.983217
[2,]  1.0603876 13.0774518  1.0228972  0.9261868  1.059799
[3,]  0.9627672  1.0228972 13.9296063  1.0444007  1.051089
[4,]  1.0371084  0.9261868  1.0444007 15.1556199  1.052573
[5,]  0.9832170  1.0597985  1.0510888  1.0525734 15.965351

-Bill

On Tue, Sep 20, 2022 at 4:24 AM Sun, John  wrote:

> Dear All,
> Reposting as plain text rather than html.
>
> I realized that R does not support finding the variance-covariance matrix
> of a random-vector. It must take two arguments. Numpy's cov doesn't give
> sensible results.
> I ask in a bigger context of finding the variance-covariance matrix of the
> vector of the dependent variables per subject which is the covariance form
> of the working-correlation matrix in GEE by Liang-Zeger (1986). Knowing it
> gives me better inference via efficiency improvement.
>
> I have not received a reply on these posts, so I ask.
>
> https://stats.stackexchange.com/questions/589022/how-to-find-covy-i-using-software-in-the-context-sum-i-1-mathrmk
>
> https://stackoverflow.com/questions/73755242/is-there-a-r-function-or-python-for-finding-the-covariance-matrix-of-a-random-ve
>
> Best regards,
> Kpjm
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question concerning side effects of treating invalid factor levels

2022-09-20 Thread Ebert,Timothy Aaron
Hi Tibor,
   I'll try again. Your problem has nothing to do with factors and everything 
to do with trying to bind a vector to a dataframe and not understanding that a 
vector must be of one class and that a column in a data frame is a vector and 
therefore must also be of one class. If you want to add a new row of data to 
your existing data frame use a new data frame with one row.

df <- data.frame(
  P = factor(c("mittels", "mit", "mittels", "ueber", "mit", "mit")),
  ANSWER = factor(c(rep("PP>OBJ", 4), rep("OBJ>PP", 2))),
  RT = round(runif(6, 7000, 16000), 0)
)

dq<-data.frame(
  P = factor("in"),
  ANSWER = factor("V>N"),
  RT = round(runif(1,7000, 16000), 0)
)

df2 <- rbind(df,dq)
df2

In this approach R kindly adds the new class to the factor variables and the 
numeric value to the numeric variable.
Keeping in mind that a vector can only be of one class will save you many 
debugging hours later on.

Tim

-Original Message-
From: Sarah Goslee  
Sent: Tuesday, September 20, 2022 9:02 AM
To: tibor.k...@rub.de
Cc: Ebert,Timothy Aaron ; r-help@r-project.org
Subject: Re: [R] Question concerning side effects of treating invalid factor 
levels

[External Email]

Hi Tibor,

No, you are misunderstanding the source of the problem. It has nothing to do 
with factors.

Instead, it has to do with the inability of a vector to hold more than one 
class.

You are using rbind() to add a new row to your data frame, but that vector is 
being coerced to character. That's what is forcing your numeric column to 
become character: you're adding a character to it.

> c("in", "V>N", round(runif(1, 7000, 16000), 0))
[1] "in""V>N"   "15709"

It has nothing whatsoever to do with factors or factor levels, and would occur 
if you were adding it to a data frame with character values.

If you want to mix types, you cannot use a vector.

c2 <- data.frame(P = "in", ANSWER = "V>N", RT = round(runif(1, 7000, 16000), 0))
> str(rbind(df, c2))
'data.frame': 7 obs. of  3 variables:
 $ P : Factor w/ 4 levels "mit","mittels",..: 2 1 2 3 1 1 4
 $ ANSWER: Factor w/ 3 levels "OBJ>PP","PP>OBJ",..: 2 2 2 2 1 1 3
 $ RT: num  10867 14808 11600 15881 8984 ...


Sarah

On Tue, Sep 20, 2022 at 8:45 AM Tibor Kiss via R-help  
wrote:
>
> Hi,
>
> this is a misunderstanding of my question. I wasn't worried about invalid 
> factor levels that produce NA. My question was why a column changes its 
> class, which I thought was a side effect. If you add a vector containing one 
> character string, the class of the whole vector becomes _chr_. And after this 
> element has been added to a column, we have two NAs for the column which are 
> factors, and a character string, which is responsible for the change of a 
> numerical vector into a character string vector (see ?c, where you find: "The 
> output type is determined from the highest type of the components in the 
> hierarchy NULL < raw < logical < integer < double < complex < character < 
> list < expression.").
>
>
> Best
>
>
> Tibor
>
>
>
> > Am 19.09.2022 um 13:59 schrieb Ebert,Timothy Aaron :
> >
> > In your example code, the variable remains a class factor, and all entries 
> > are valid. The variables will behave as expected given the factor levels in 
> > the original dataframe.
> >
> > (At least on my system R 4.2, in RStudio, in Windows) R returns a couple of 
> > error messages warning me that I was bad.
> > What you get is NA for "not available", or "not appropriate" or a missing 
> > value. You gave the system an invalid factor level so it was entered as 
> > missing. If you get data that has a new factor level, you need to tell R to 
> > expect a new factor level first.
> >
> > levels(f1) <- c(levels(f1),"New Level")
> > levels(f1) <- c(levels(f1),c("NL1","NL2"))
> >
> >
> > Tim
> > -Original Message-
> > From: R-help  On Behalf Of Tibor Kiss 
> > via R-help
> > Sent: Monday, September 19, 2022 6:11 AM
> > To: r-help@r-project.org
> > Subject: [R] Question concerning side effects of treating invalid 
> > factor levels
> >
> > [External Email]
> >
> > Dear List members,
> >
> > I have tried now for several times to find out about a side effect of 
> > treating invalid factor levels, but did not find an answer. Various answers 
> > on stackexchange etc. produce the stuff that irritates me without even 
> > mentioning it.
> > So I am asking the list (apologies if this has been treated in the past).
> >
> > If you add an invalid factor level to a column in a data frame, this has 
> > the side effect of turning a numerical column into a column with character 
> > strings. Here is a simple example:
> >
> >> df <- data.frame(
> >P = factor(c("mittels", "mit", "mittels", "ueber", "mit", "mit")),
> >ANSWER = factor(c(rep("PP>OBJ", 4), rep("OBJ>PP", 2))),
> >RT = round(runif(6, 7000, 16000), 0))
> >
> >> str(df)
> > 'data.frame':   6 obs. of  3 variables:
> > $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1
> > $ ANSWER: Factor w/ 2 levels "

Re: [R] Question concerning side effects of treating invalid factor levels

2022-09-20 Thread Sarah Goslee
Hi Tibor,

No, you are misunderstanding the source of the problem. It has nothing
to do with factors.

Instead, it has to do with the inability of a vector to hold more than
one class.

You are using rbind() to add a new row to your data frame, but that
vector is being coerced to character. That's what is forcing your
numeric column to become character: you're adding a character to it.

> c("in", "V>N", round(runif(1, 7000, 16000), 0))
[1] "in""V>N"   "15709"

It has nothing whatsoever to do with factors or factor levels, and
would occur if you were adding it to a data frame with character
values.

If you want to mix types, you cannot use a vector.

c2 <- data.frame(P = "in", ANSWER = "V>N", RT = round(runif(1, 7000, 16000), 0))
> str(rbind(df, c2))
'data.frame': 7 obs. of  3 variables:
 $ P : Factor w/ 4 levels "mit","mittels",..: 2 1 2 3 1 1 4
 $ ANSWER: Factor w/ 3 levels "OBJ>PP","PP>OBJ",..: 2 2 2 2 1 1 3
 $ RT: num  10867 14808 11600 15881 8984 ...


Sarah

On Tue, Sep 20, 2022 at 8:45 AM Tibor Kiss via R-help
 wrote:
>
> Hi,
>
> this is a misunderstanding of my question. I wasn’t worried about invalid 
> factor levels that produce NA. My question was why a column changes its 
> class, which I thought was a side effect. If you add a vector containing one 
> character string, the class of the whole vector becomes _chr_. And after this 
> element has been added to a column, we have two NAs for the column which are 
> factors, and a character string, which is responsible for the change of a 
> numerical vector into a character string vector (see ?c, where you find: "The 
> output type is determined from the highest type of the components in the 
> hierarchy NULL < raw < logical < integer < double < complex < character < 
> list < expression.“).
>
>
> Best
>
>
> Tibor
>
>
>
> > Am 19.09.2022 um 13:59 schrieb Ebert,Timothy Aaron :
> >
> > In your example code, the variable remains a class factor, and all entries 
> > are valid. The variables will behave as expected given the factor levels in 
> > the original dataframe.
> >
> > (At least on my system R 4.2, in RStudio, in Windows) R returns a couple of 
> > error messages warning me that I was bad.
> > What you get is NA for "not available", or "not appropriate" or a missing 
> > value. You gave the system an invalid factor level so it was entered as 
> > missing. If you get data that has a new factor level, you need to tell R to 
> > expect a new factor level first.
> >
> > levels(f1) <- c(levels(f1),"New Level")
> > levels(f1) <- c(levels(f1),c("NL1","NL2"))
> >
> >
> > Tim
> > -Original Message-
> > From: R-help  On Behalf Of Tibor Kiss via 
> > R-help
> > Sent: Monday, September 19, 2022 6:11 AM
> > To: r-help@r-project.org
> > Subject: [R] Question concerning side effects of treating invalid factor 
> > levels
> >
> > [External Email]
> >
> > Dear List members,
> >
> > I have tried now for several times to find out about a side effect of 
> > treating invalid factor levels, but did not find an answer. Various answers 
> > on stackexchange etc. produce the stuff that irritates me without even 
> > mentioning it.
> > So I am asking the list (apologies if this has been treated in the past).
> >
> > If you add an invalid factor level to a column in a data frame, this has 
> > the side effect of turning a numerical column into a column with character 
> > strings. Here is a simple example:
> >
> >> df <- data.frame(
> >P = factor(c("mittels", "mit", "mittels", "ueber", "mit", "mit")),
> >ANSWER = factor(c(rep("PP>OBJ", 4), rep("OBJ>PP", 2))),
> >RT = round(runif(6, 7000, 16000), 0))
> >
> >> str(df)
> > 'data.frame':   6 obs. of  3 variables:
> > $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1
> > $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1
> > $ RT: num  11157 13719 14388 14527 14686 ..
> >
> >> df <- rbind(df, c("in", "V>N", round(runif(1, 7000, 16000), 0)))
> >
> >> str(df)
> > 'data.frame':   7 obs. of  3 variables:
> > $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1 NA
> > $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1 NA
> > $ RT: chr  "11478" "15819" "8305" "8852" ...
> >
> > You see that RT has changed from _num_ to _chr_ as a side effect of adding 
> > the invalid factor level as NA. I would appreciate understanding what the 
> > purpose of the type coercion is.
> >
> > Thanks in advance
> >
> >
> > Tibor
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C6ee1a1f50c14442beef508da9a301bde%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637991828670135028%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=sNDYEJKhjSu%2FtrTIwZx5yVemKgDheQYXLrcQqJ2mOgo%3D&reserved=0
> > PLEA

Re: [R] Question concerning side effects of treating invalid factor levels

2022-09-20 Thread Tibor Kiss via R-help
Hi, 

this is a misunderstanding of my question. I wasn’t worried about invalid 
factor levels that produce NA. My question was why a column changes its class, 
which I thought was a side effect. If you add a vector containing one character 
string, the class of the whole vector becomes _chr_. And after this element has 
been added to a column, we have two NAs for the column which are factors, and a 
character string, which is responsible for the change of a numerical vector 
into a character string vector (see ?c, where you find: "The output type is 
determined from the highest type of the components in the hierarchy NULL < raw 
< logical < integer < double < complex < character < list < expression.“).

 
Best


Tibor



> Am 19.09.2022 um 13:59 schrieb Ebert,Timothy Aaron :
> 
> In your example code, the variable remains a class factor, and all entries 
> are valid. The variables will behave as expected given the factor levels in 
> the original dataframe.
> 
> (At least on my system R 4.2, in RStudio, in Windows) R returns a couple of 
> error messages warning me that I was bad.
> What you get is NA for "not available", or "not appropriate" or a missing 
> value. You gave the system an invalid factor level so it was entered as 
> missing. If you get data that has a new factor level, you need to tell R to 
> expect a new factor level first.
> 
> levels(f1) <- c(levels(f1),"New Level")
> levels(f1) <- c(levels(f1),c("NL1","NL2"))
> 
> 
> Tim
> -Original Message-
> From: R-help  On Behalf Of Tibor Kiss via R-help
> Sent: Monday, September 19, 2022 6:11 AM
> To: r-help@r-project.org
> Subject: [R] Question concerning side effects of treating invalid factor 
> levels
> 
> [External Email]
> 
> Dear List members,
> 
> I have tried now for several times to find out about a side effect of 
> treating invalid factor levels, but did not find an answer. Various answers 
> on stackexchange etc. produce the stuff that irritates me without even 
> mentioning it.
> So I am asking the list (apologies if this has been treated in the past).
> 
> If you add an invalid factor level to a column in a data frame, this has the 
> side effect of turning a numerical column into a column with character 
> strings. Here is a simple example:
> 
>> df <- data.frame(
>P = factor(c("mittels", "mit", "mittels", "ueber", "mit", "mit")),
>ANSWER = factor(c(rep("PP>OBJ", 4), rep("OBJ>PP", 2))),
>RT = round(runif(6, 7000, 16000), 0))
> 
>> str(df)
> 'data.frame':   6 obs. of  3 variables:
> $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1
> $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1
> $ RT: num  11157 13719 14388 14527 14686 ..
> 
>> df <- rbind(df, c("in", "V>N", round(runif(1, 7000, 16000), 0)))
> 
>> str(df)
> 'data.frame':   7 obs. of  3 variables:
> $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1 NA
> $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1 NA
> $ RT: chr  "11478" "15819" "8305" "8852" ...
> 
> You see that RT has changed from _num_ to _chr_ as a side effect of adding 
> the invalid factor level as NA. I would appreciate understanding what the 
> purpose of the type coercion is.
> 
> Thanks in advance
> 
> 
> Tibor
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C6ee1a1f50c14442beef508da9a301bde%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637991828670135028%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=sNDYEJKhjSu%2FtrTIwZx5yVemKgDheQYXLrcQqJ2mOgo%3D&reserved=0
> PLEASE do read the posting guide 
> https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C6ee1a1f50c14442beef508da9a301bde%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637991828670135028%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=AP%2B4fa5pvbGr3IfwdiQvjXwkOdY90CIWIWWWmpIHH7w%3D&reserved=0
> and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Question concerning side effects of treating invalid factor levels

2022-09-20 Thread Tibor Kiss via R-help
Dear Eric,

thank you very much. I wouldn’t have come to the idea to look up the help page 
for _c()_, which of course explains the coercion to the highest type. 

Best

T.


> Am 19.09.2022 um 13:31 schrieb Eric Berger :
> 
> You are misinterpreting what is going on.
> The rbind command includes c(char, char, int) which produces a
> character vector of length 3.
> This is what you are rbind-ing which changes the type of the RT column.
> 
> If you do rbind(df, data.frame(P="in", ANSWER="V>N",
> RT=round(runif(1,7000,16000),0)))
> you will see that everything is fine. (New factor values are created.)
> 
> HTH,
> Eric
> 
> On Mon, Sep 19, 2022 at 2:14 PM Tibor Kiss via R-help
>  wrote:
>> 
>> Dear List members,
>> 
>> I have tried now for several times to find out about a side effect of 
>> treating invalid factor levels, but did not find an answer. Various answers 
>> on stackexchange etc. produce the stuff that irritates me without even 
>> mentioning it.
>> So I am asking the list (apologies if this has been treated in the past).
>> 
>> If you add an invalid factor level to a column in a data frame, this has the 
>> side effect of turning a numerical column into a column with character 
>> strings. Here is a simple example:
>> 
>>> df <- data.frame(
>>P = factor(c("mittels", "mit", "mittels", "ueber", "mit", "mit")),
>>ANSWER = factor(c(rep("PP>OBJ", 4), rep("OBJ>PP", 2))),
>>RT = round(runif(6, 7000, 16000), 0))
>> 
>>> str(df)
>> 'data.frame':   6 obs. of  3 variables:
>> $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1
>> $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1
>> $ RT: num  11157 13719 14388 14527 14686 ..
>> 
>>> df <- rbind(df, c("in", "V>N", round(runif(1, 7000, 16000), 0)))
>> 
>>> str(df)
>> 'data.frame':   7 obs. of  3 variables:
>> $ P : Factor w/ 3 levels "mit","mittels",..: 2 1 2 3 1 1 NA
>> $ ANSWER: Factor w/ 2 levels "OBJ>PP","PP>OBJ": 2 2 2 2 1 1 NA
>> $ RT: chr  "11478" "15819" "8305" "8852" …
>> 
>> You see that RT has changed from _num_ to _chr_ as a side effect of adding 
>> the invalid factor level as NA. I would appreciate understanding what the 
>> purpose of the type coercion is.
>> 
>> Thanks in advance
>> 
>> 
>> Tibor
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to find the variance-covariance matrix of a random-vector using R

2022-09-20 Thread Sun, John
Dear All,
Reposting as plain text rather than html. 

I realized that R does not support finding the variance-covariance matrix of a 
random-vector. It must take two arguments. Numpy's cov doesn't give sensible 
results.
I ask in a bigger context of finding the variance-covariance matrix of the 
vector of the dependent variables per subject which is the covariance form of 
the working-correlation matrix in GEE by Liang-Zeger (1986). Knowing it gives 
me better inference via efficiency improvement.

I have not received a reply on these posts, so I ask.
https://stats.stackexchange.com/questions/589022/how-to-find-covy-i-using-software-in-the-context-sum-i-1-mathrmk
 
https://stackoverflow.com/questions/73755242/is-there-a-r-function-or-python-for-finding-the-covariance-matrix-of-a-random-ve

Best regards,
Kpjm

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Need help plotting

2022-09-20 Thread Rui Barradas

Hello,

Now with data, here are base R and ggplot2 plots.


b <- read.table(text=
"Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2 
MVOCMpm10 Mpm2.5 Mpm1
 18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00 
 21
 18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00 
 21
 18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00 
 21",

  header=TRUE,stringsAsFactors=FALSE)


# This base R plot needs package chron
library(chron)

# first make a real time class column
b$Dtime2 <- paste(b$Dtime, "00", sep = ":")
b$Dtime2 <- as.times(b$Dtime2)

# get the plot height and make room for
# the legend by adding 2 to y max
ylim <- range(unlist(b[c("DNO2", "MNO2")])) + c(0, 2)

# now plot one line
plot(DNO2 ~ Dtime2, b, type = "b", col = "orange", ylim = ylim)
# add the second line
points(MNO2 ~ Dtime2, b, type = "b", col = "skyblue")
# and the horizontal legend at the top center
legend("top", legend = c("DNO2", "MNO2"), horiz = TRUE,
   lty = "solid", col = c("orange", "skyblue"))


#---

library(ggplot2)
library(dplyr)
library(tidyr)

b %>%
  mutate(Dtime = paste(Sys.Date(), Dtime),
Dtime = as.POSIXct(Dtime)) %>%
  select(Dtime, DNO2, MNO2) %>%
  # reshape to long format
  pivot_longer(-Dtime, names_to = "NO2") %>%
  # now plot
  ggplot(aes(Dtime, value, color = NO2)) +
  geom_line() +
  geom_point() +
  scale_color_manual(values = c("orange", "skyblue")) +
  # make datetime labels
  scale_x_datetime(date_breaks = "1 mins", date_labels = "%H:%M") +
  theme_bw()


Hope this helps,

Rui Barradas


Às 08:37 de 20/09/2022, Jim Lemon escreveu:

Hi David,
I'm back home again. Try this:

b<-read.table(text=
"Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2 MVOCMpm10 Mpm2.5 Mpm1
  18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00  21
  18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00  21
  18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00  2
1",
  header=TRUE,stringsAsFactors=FALSE)
b$POSIXtime<-strptime(paste("2022-09-20",b$Dtime),"%Y-%m-%d %H:%M")
png("DFPNO2.png")
plot(b$POSIXtime,b$DNO2,type="b",main="NO2 readings (2022-09-20)",
  xlab="Date/time",ylab="NO2",ylim=range(c(b$DNO2,b$MNO2)),
  pch=19,col="red")
  points(b$POSIXtime,b$MNO2,type="b",pch=19,col="blue")
  legend("center",legend=c("DNO2","MNO2"),pch=19,col=c("red","blue"))
dev.off()

If you have more than one day, it will show up on the x axis. You can
also format the tick labels if you want the full dates for only one
day.

Jim

PS thanks Avi

On Tue, Sep 20, 2022 at 4:49 PM Parkhurst, David  wrote:


Thank you.

DFP (iPad)


On Sep 19, 2022, at 8:15 AM, Ebert,Timothy Aaron  wrote:

My version of this email has a bunch of ? that I do not know how to interpret. 
Emails to this group need to be in plain text. HTML content is deleted or 
converted and impossible or at least difficult to interpret.

Do not share confidential data. Please change some numbers or variable names 
and share that.
If this helps:
1) Make sure your time variable is a datetime object.
2) At least in ggplot it should now behave as expected.
ggplot(df, aes(y=NO2, x=datetime)) + geom_point()

That will be a start as a scatterplot, but the graph can be customized or 
changed if scatterplot was not desired.

Tim

-Original Message-
From: R-help  On Behalf Of Parkhurst, David
Sent: Sunday, September 18, 2022 4:27 PM
To: r-help@r-project.org
Subject: [R] Need help plotting

[External Email]

I�ve been retired since �06 and have forgotten most of R.  Now I have a use for 
it, with some data from Bloomington�s Environmental Commission.

I have a dataframe (obtained from read.csv) that contains numerous columns, 
including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air 
quality instruments.

I�d like a plot of both the NO2 measurements against time.  I be happy to use 
either ordinary R plots or ggplot2 ones, if that would be a better way.  I�d 
much appreciate help.

[[alternative HTML version deleted]]


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, re

Re: [R] Need help plotting

2022-09-20 Thread Jim Lemon
Hi David,
I'm back home again. Try this:

b<-read.table(text=
"Dtime DNO2 DVOC Dpm10Dpm2.5 Dpm1 Mtime MNO2 MVOCMpm10 Mpm2.5 Mpm1
 18:00   28  164  81.34773 24.695435   14 18:00   19  151 3.00  21
 18:01   27  163  74.44034 23.751198   14 18:01   20  148 3.00  21
 18:02   30  160  72.21975 22.463129   13 18:02   19  150 3.00  21",
 header=TRUE,stringsAsFactors=FALSE)
b$POSIXtime<-strptime(paste("2022-09-20",b$Dtime),"%Y-%m-%d %H:%M")
png("DFPNO2.png")
plot(b$POSIXtime,b$DNO2,type="b",main="NO2 readings (2022-09-20)",
 xlab="Date/time",ylab="NO2",ylim=range(c(b$DNO2,b$MNO2)),
 pch=19,col="red")
 points(b$POSIXtime,b$MNO2,type="b",pch=19,col="blue")
 legend("center",legend=c("DNO2","MNO2"),pch=19,col=c("red","blue"))
dev.off()

If you have more than one day, it will show up on the x axis. You can
also format the tick labels if you want the full dates for only one
day.

Jim

PS thanks Avi

On Tue, Sep 20, 2022 at 4:49 PM Parkhurst, David  wrote:
>
> Thank you.
>
> DFP (iPad)
>
> > On Sep 19, 2022, at 8:15 AM, Ebert,Timothy Aaron  wrote:
> >
> > My version of this email has a bunch of ? that I do not know how to 
> > interpret. Emails to this group need to be in plain text. HTML content is 
> > deleted or converted and impossible or at least difficult to interpret.
> >
> > Do not share confidential data. Please change some numbers or variable 
> > names and share that.
> > If this helps:
> > 1) Make sure your time variable is a datetime object.
> > 2) At least in ggplot it should now behave as expected.
> > ggplot(df, aes(y=NO2, x=datetime)) + geom_point()
> >
> > That will be a start as a scatterplot, but the graph can be customized or 
> > changed if scatterplot was not desired.
> >
> > Tim
> >
> > -Original Message-
> > From: R-help  On Behalf Of Parkhurst, David
> > Sent: Sunday, September 18, 2022 4:27 PM
> > To: r-help@r-project.org
> > Subject: [R] Need help plotting
> >
> > [External Email]
> >
> > I�ve been retired since �06 and have forgotten most of R.  Now I have a use 
> > for it, with some data from Bloomington�s Environmental Commission.
> >
> > I have a dataframe (obtained from read.csv) that contains numerous columns, 
> > including time (in Excel�s 18:00 format), and DNO2, and MNO2 from two air 
> > quality instruments.
> >
> > I�d like a plot of both the NO2 measurements against time.  I be happy to 
> > use either ordinary R plots or ggplot2 ones, if that would be a better way. 
> >  I�d much appreciate help.
> >
> >[[alternative HTML version deleted]]
> >
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.