Re: [R] Converting a list to a data frame

2021-07-24 Thread Duncan Murdoch

On 24/07/2021 5:40 p.m., Rui Barradas wrote:

Hello,

No, it's not possible to work with a matrix in ggplot2.
Not even with an object of class "list".


If that's the main thing Jeff is doing, then he should convert to a 
dataframe.  But it *is* possible to work with the original matrix in 
ggplot2, just not very natural:




l <- list(x=1:5, y=1:5)
d <- as.data.frame(l)
m <- as.matrix(d)

library(ggplot2)
ggplot(l, aes(x, y)) + geom_point()  # Error
ggplot(d, aes(x, y)) + geom_point()  # OK, as expected
ggplot(m, aes(x, y)) + geom_point()  # Error


ggplot(NULL, aes(x=m[,"x"], y=m[,"y"])) + geom_point() # OK

Duncan Murdoch





Hope this helps,

Rui Barradas


Às 22:31 de 24/07/21, Jeff Reichman escreveu:

Duncan

I need to plot the results (ggplot2) and I'm thinking I can only use a data.frame object 
in ggplot2. It is a rath r large "list" over 1 million rows. It is possible to 
work with a matrix in ggplot2?

Jeff

-Original Message-
From: Duncan Murdoch 
Sent: Saturday, July 24, 2021 12:03 PM
To: reichm...@sbcglobal.net; R-help@r-project.org
Subject: Re: [R] Converting a list to a data frame

Others have shown you how to extract the matrix and convert it to a dataframe.  
My only addition is to suggest that you don't do this:
matrix methods are often much more efficient than dataframe methods, so if you 
can work with the matrix without conversion, you'll often find things run a lot 
faster.

Duncan Murdoch

On 24/07/2021 9:18 a.m., Jeff Reichman wrote:

How does one convert a list into a data frame?




str(weight_chains)


List of 1

$ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...

 ..- attr(*, "dimnames")=List of 2

 .. ..$ : NULL

 .. ..$ : chr [1:3] "a" "b" "s"

 ..- attr(*, "mcpar")= num [1:3] 1001 101000 1

- attr(*, "class")= chr "mcmc.list"




Such that ..







weight_chains



  a b s

1 -104.72512 1.0141407  9.369227

2 -104.52297 1.0167432  9.131354

3 -104.72669 1.0139528  9.219877





[[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, reproducible code.


Re: [R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
Thanks for the tips

-Original Message-
From: Rui Barradas  
Sent: Saturday, July 24, 2021 11:40 AM
To: reichm...@sbcglobal.net; R-help@r-project.org
Subject: Re: [R] Converting a list to a data frame

Hello,

This should do it:


as.data.frame(weight_chains$mcmc)


The only list member already has a dim attribute of length 2 and dimnames' 2nd 
member are the colnames, just coerce to df.

Hope this helps,

Rui Barradas

Às 14:18 de 24/07/21, Jeff Reichman escreveu:
> How does one convert a list into a data frame?
> 
>   
> 
>> str(weight_chains)
> 
> List of 1
> 
> $ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...
> 
>..- attr(*, "dimnames")=List of 2
> 
>.. ..$ : NULL
> 
>.. ..$ : chr [1:3] "a" "b" "s"
> 
>..- attr(*, "mcpar")= num [1:3] 1001 101000 1
> 
> - attr(*, "class")= chr "mcmc.list"
> 
>   
> 
> Such that ..
> 
>   
> 
>>
> 
> weight_chains
> 
> 
> 
> a b s
> 
> 1 -104.72512 1.0141407  9.369227
> 
> 2 -104.52297 1.0167432  9.131354
> 
> 3 -104.72669 1.0139528  9.219877
> 
>   
> 
> 
>   [[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.


Re: [R] Converting a list to a data frame

2021-07-24 Thread Rui Barradas

Hello,

No, it's not possible to work with a matrix in ggplot2.
Not even with an object of class "list".



l <- list(x=1:5, y=1:5)
d <- as.data.frame(l)
m <- as.matrix(d)

library(ggplot2)
ggplot(l, aes(x, y)) + geom_point()  # Error
ggplot(d, aes(x, y)) + geom_point()  # OK, as expected
ggplot(m, aes(x, y)) + geom_point()  # Error



Hope this helps,

Rui Barradas


Às 22:31 de 24/07/21, Jeff Reichman escreveu:

Duncan

I need to plot the results (ggplot2) and I'm thinking I can only use a data.frame object 
in ggplot2. It is a rath r large "list" over 1 million rows. It is possible to 
work with a matrix in ggplot2?

Jeff

-Original Message-
From: Duncan Murdoch 
Sent: Saturday, July 24, 2021 12:03 PM
To: reichm...@sbcglobal.net; R-help@r-project.org
Subject: Re: [R] Converting a list to a data frame

Others have shown you how to extract the matrix and convert it to a dataframe.  
My only addition is to suggest that you don't do this:
matrix methods are often much more efficient than dataframe methods, so if you 
can work with the matrix without conversion, you'll often find things run a lot 
faster.

Duncan Murdoch

On 24/07/2021 9:18 a.m., Jeff Reichman wrote:

How does one convert a list into a data frame?

   


str(weight_chains)


List of 1

$ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...

..- attr(*, "dimnames")=List of 2

.. ..$ : NULL

.. ..$ : chr [1:3] "a" "b" "s"

..- attr(*, "mcpar")= num [1:3] 1001 101000 1

- attr(*, "class")= chr "mcmc.list"

   


Such that ..

   





weight_chains



 a b s

1 -104.72512 1.0141407  9.369227

2 -104.52297 1.0167432  9.131354

3 -104.72669 1.0139528  9.219877

   



[[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, reproducible code.


Re: [R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
Duncan

I need to plot the results (ggplot2) and I'm thinking I can only use a 
data.frame object in ggplot2. It is a rath r large "list" over 1 million rows. 
It is possible to work with a matrix in ggplot2?

Jeff

-Original Message-
From: Duncan Murdoch  
Sent: Saturday, July 24, 2021 12:03 PM
To: reichm...@sbcglobal.net; R-help@r-project.org
Subject: Re: [R] Converting a list to a data frame

Others have shown you how to extract the matrix and convert it to a dataframe.  
My only addition is to suggest that you don't do this: 
matrix methods are often much more efficient than dataframe methods, so if you 
can work with the matrix without conversion, you'll often find things run a lot 
faster.

Duncan Murdoch

On 24/07/2021 9:18 a.m., Jeff Reichman wrote:
> How does one convert a list into a data frame?
> 
>   
> 
>> str(weight_chains)
> 
> List of 1
> 
> $ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...
> 
>..- attr(*, "dimnames")=List of 2
> 
>.. ..$ : NULL
> 
>.. ..$ : chr [1:3] "a" "b" "s"
> 
>..- attr(*, "mcpar")= num [1:3] 1001 101000 1
> 
> - attr(*, "class")= chr "mcmc.list"
> 
>   
> 
> Such that ..
> 
>   
> 
>>
> 
> weight_chains
> 
> 
> 
> a b s
> 
> 1 -104.72512 1.0141407  9.369227
> 
> 2 -104.52297 1.0167432  9.131354
> 
> 3 -104.72669 1.0139528  9.219877
> 
>   
> 
> 
>   [[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.


Re: [R] Sin curve question

2021-07-24 Thread Rui Barradas

Hello,

You can use stat_function, it will take care of all the details, all you 
have to do is to pass xlim.



library(ggplot2)
library(cowplot)

ggplot() +
  stat_function(fun = sin, xlim = c(0, pi)) +
  xlab("x") +
  ylab("sin(x)") +
  scale_x_continuous(breaks = seq(0, pi, pi/6), labels = seq(0, 180, 30)) +
  ggtitle("sin(x) vs x", subtitle = "x is in degrees") +
  theme_cowplot()


Hope this helps,

Rui Barradas

Às 19:41 de 24/07/21, Thomas Subia via R-help escreveu:

Colleagues,

Here is my code which plots sin(x) vs x, for angles between 0 and 180
degrees.

library(ggplot2)
library(REdaS)
copdat$degrees <- c(0,45,90,135,180)
copdat$radians <- deg2rad(copdat$degrees)
copdat$sin_x <- sin(copdat$radians)

ggplot(copdat,aes(x=degrees,y=sin_x))+
   geom_point(size = 2)+ geom_line()+
   theme_cowplot()+xlab("x")+
   ylab("sin(x)")+
   scale_x_continuous(breaks=seq(0,180,30))+
   ggtitle("sin(x) vs x\nx is in degrees")

My trig students would prefer a curved line plot similar to what can be
plotted with Excel smooth line functionality.
I wanted to provide a relatively simple R script using ggplot to do this
without having to resort to fitting a sine curve to these points.

Some guidance would be appreciated.

__
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.


Re: [R] Sin curve question

2021-07-24 Thread Jeff Newmiller
This is not excel-help, but to the best of my knowledge Excel interpolates with 
splines when you select curved point interpolation.

R, being primarily a science tool rather than a business tool, assumes you want 
to be precise about how new points are to be interpolated between original data 
points. Thus, the task of building the spline and deciding how close the points 
in that interpolation need to be is typically left to the user. If the user 
knows that the points are part of a periodic continuous function and 
extrapolation is desired, then choosing a fourier series may be a better choice 
than a spline. But the data you have provided is insufficient to support a 
fourier analysis, so there is some sophisticated math in between you and your 
goal unless you build in heuristics about how to interpolate within these 
points, or just live with whatever a spline function will give you... but the 
choice is yours to make.

On July 24, 2021 11:41:05 AM PDT, Thomas Subia via R-help 
 wrote:
>Colleagues,
>
>Here is my code which plots sin(x) vs x, for angles between 0 and 180
>degrees.
>
>library(ggplot2)
>library(REdaS)
>copdat$degrees <- c(0,45,90,135,180)
>copdat$radians <- deg2rad(copdat$degrees)
>copdat$sin_x <- sin(copdat$radians)
>
>ggplot(copdat,aes(x=degrees,y=sin_x))+
>  geom_point(size = 2)+ geom_line()+
>  theme_cowplot()+xlab("x")+
>  ylab("sin(x)")+
>  scale_x_continuous(breaks=seq(0,180,30))+
>  ggtitle("sin(x) vs x\nx is in degrees")
>
>My trig students would prefer a curved line plot similar to what can be
>plotted with Excel smooth line functionality.
>I wanted to provide a relatively simple R script using ggplot to do
>this
>without having to resort to fitting a sine curve to these points.
>
>Some guidance would be appreciated.
>
>__
>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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] Sin curve question

2021-07-24 Thread Spencer Graves

plot(sin, to=pi) # also works but with x labeled in radians.


# With x axis labeled in degrees
plot(sin, to=pi, axes=FALSE)
axis(2)
lbls <- seq(0, 180, 30)
axis(1, pi*lbls/180, lbls)


	  This can probably be done in ggplot2, but I don't know how off the 
top of my head.



  Hope this helps.
  Spencer


On 7/24/21 2:04 PM, Eric Berger wrote:

Alternatively with base graphics

N <- 500 ## number of points (arbitrary)
degrees <- seq(from=0,to=180,length=N)
degreesToRadians <- function(d) { pi * d / 180.0}  ## vectorIzed!
plot(x=degrees,y=sin(degreesToRadians(degrees)),type='l',
  xlab="x",ylab="sin(x)",main="sin(x) vs x\nx is in degrees")


On Sat, Jul 24, 2021 at 9:52 PM Sorkin, John 
wrote:


Try something like the following

copdat$degrees <- c(1:180)

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and
Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior
to faxing)

On Jul 24, 2021, at 2:41 PM, Thomas Subia via R-help 
wrote:

Colleagues,

Here is my code which plots sin(x) vs x, for angles between 0 and 180
degrees.

library(ggplot2)
library(REdaS)
copdat$degrees <- c(0,45,90,135,180)
copdat$radians <- deg2rad(copdat$degrees)
copdat$sin_x <- sin(copdat$radians)

ggplot(copdat,aes(x=degrees,y=sin_x))+
  geom_point(size = 2)+ geom_line()+
  theme_cowplot()+xlab("x")+
  ylab("sin(x)")+
  scale_x_continuous(breaks=seq(0,180,30))+
  ggtitle("sin(x) vs x\nx is in degrees")

My trig students would prefer a curved line plot similar to what can be
plotted with Excel smooth line functionality.
I wanted to provide a relatively simple R script using ggplot to do this
without having to resort to fitting a sine curve to these points.

Some guidance would be appreciated.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see

https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=90qApIoS6rwqkQuKPzy3x2AUPntuJ2W%2FtJgPGfiddEI%3Dreserved=0
PLEASE do read the posting guide
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=s9YIcjlEo4MvI6hcX%2FkV4gwJJKa172QrPEnHsqTiRa8%3Dreserved=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.



[[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.


Re: [R] Sin curve question

2021-07-24 Thread Eric Berger
Alternatively with base graphics

N <- 500 ## number of points (arbitrary)
degrees <- seq(from=0,to=180,length=N)
degreesToRadians <- function(d) { pi * d / 180.0}  ## vectorIzed!
plot(x=degrees,y=sin(degreesToRadians(degrees)),type='l',
 xlab="x",ylab="sin(x)",main="sin(x) vs x\nx is in degrees")


On Sat, Jul 24, 2021 at 9:52 PM Sorkin, John 
wrote:

> Try something like the following
>
> copdat$degrees <- c(1:180)
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior
> to faxing)
>
> On Jul 24, 2021, at 2:41 PM, Thomas Subia via R-help 
> wrote:
>
> Colleagues,
>
> Here is my code which plots sin(x) vs x, for angles between 0 and 180
> degrees.
>
> library(ggplot2)
> library(REdaS)
> copdat$degrees <- c(0,45,90,135,180)
> copdat$radians <- deg2rad(copdat$degrees)
> copdat$sin_x <- sin(copdat$radians)
>
> ggplot(copdat,aes(x=degrees,y=sin_x))+
>  geom_point(size = 2)+ geom_line()+
>  theme_cowplot()+xlab("x")+
>  ylab("sin(x)")+
>  scale_x_continuous(breaks=seq(0,180,30))+
>  ggtitle("sin(x) vs x\nx is in degrees")
>
> My trig students would prefer a curved line plot similar to what can be
> plotted with Excel smooth line functionality.
> I wanted to provide a relatively simple R script using ggplot to do this
> without having to resort to fitting a sine curve to these points.
>
> Some guidance would be appreciated.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=90qApIoS6rwqkQuKPzy3x2AUPntuJ2W%2FtJgPGfiddEI%3Dreserved=0
> PLEASE do read the posting guide
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=s9YIcjlEo4MvI6hcX%2FkV4gwJJKa172QrPEnHsqTiRa8%3Dreserved=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.
>

[[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] Sin curve question

2021-07-24 Thread Sorkin, John
Try something like the following

copdat$degrees <- c(1:180)

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to 
faxing)

On Jul 24, 2021, at 2:41 PM, Thomas Subia via R-help  
wrote:

Colleagues,

Here is my code which plots sin(x) vs x, for angles between 0 and 180
degrees.

library(ggplot2)
library(REdaS)
copdat$degrees <- c(0,45,90,135,180)
copdat$radians <- deg2rad(copdat$degrees)
copdat$sin_x <- sin(copdat$radians)

ggplot(copdat,aes(x=degrees,y=sin_x))+
 geom_point(size = 2)+ geom_line()+
 theme_cowplot()+xlab("x")+
 ylab("sin(x)")+
 scale_x_continuous(breaks=seq(0,180,30))+
 ggtitle("sin(x) vs x\nx is in degrees")

My trig students would prefer a curved line plot similar to what can be
plotted with Excel smooth line functionality.
I wanted to provide a relatively simple R script using ggplot to do this
without having to resort to fitting a sine curve to these points.

Some guidance would be appreciated.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-helpdata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=90qApIoS6rwqkQuKPzy3x2AUPntuJ2W%2FtJgPGfiddEI%3Dreserved=0
PLEASE do read the posting guide 
https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.htmldata=04%7C01%7CJSorkin%40som.umaryland.edu%7C1ffa4922f2ba41588da908d94ed2a982%7C717009a620de461a88940312a395cac9%7C0%7C0%7C637627488997910453%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=s9YIcjlEo4MvI6hcX%2FkV4gwJJKa172QrPEnHsqTiRa8%3Dreserved=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.


[R] Sin curve question

2021-07-24 Thread Thomas Subia via R-help
Colleagues,

Here is my code which plots sin(x) vs x, for angles between 0 and 180
degrees.

library(ggplot2)
library(REdaS)
copdat$degrees <- c(0,45,90,135,180)
copdat$radians <- deg2rad(copdat$degrees)
copdat$sin_x <- sin(copdat$radians)

ggplot(copdat,aes(x=degrees,y=sin_x))+
  geom_point(size = 2)+ geom_line()+
  theme_cowplot()+xlab("x")+
  ylab("sin(x)")+
  scale_x_continuous(breaks=seq(0,180,30))+
  ggtitle("sin(x) vs x\nx is in degrees")

My trig students would prefer a curved line plot similar to what can be
plotted with Excel smooth line functionality.
I wanted to provide a relatively simple R script using ggplot to do this
without having to resort to fitting a sine curve to these points.

Some guidance would be appreciated.

__
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] Converting a list to a data frame

2021-07-24 Thread Duncan Murdoch
Others have shown you how to extract the matrix and convert it to a 
dataframe.  My only addition is to suggest that you don't do this: 
matrix methods are often much more efficient than dataframe methods, so 
if you can work with the matrix without conversion, you'll often find 
things run a lot faster.


Duncan Murdoch

On 24/07/2021 9:18 a.m., Jeff Reichman wrote:

How does one convert a list into a data frame?

  


str(weight_chains)


List of 1

$ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...

   ..- attr(*, "dimnames")=List of 2

   .. ..$ : NULL

   .. ..$ : chr [1:3] "a" "b" "s"

   ..- attr(*, "mcpar")= num [1:3] 1001 101000 1

- attr(*, "class")= chr "mcmc.list"

  


Such that ..

  





weight_chains



a b s

1 -104.72512 1.0141407  9.369227

2 -104.52297 1.0167432  9.131354

3 -104.72669 1.0139528  9.219877

  



[[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.


Re: [R] Converting a list to a data frame

2021-07-24 Thread Rui Barradas

Hello,

This should do it:


as.data.frame(weight_chains$mcmc)


The only list member already has a dim attribute of length 2 and 
dimnames' 2nd member are the colnames, just coerce to df.


Hope this helps,

Rui Barradas

Às 14:18 de 24/07/21, Jeff Reichman escreveu:

How does one convert a list into a data frame?

  


str(weight_chains)


List of 1

$ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...

   ..- attr(*, "dimnames")=List of 2

   .. ..$ : NULL

   .. ..$ : chr [1:3] "a" "b" "s"

   ..- attr(*, "mcpar")= num [1:3] 1001 101000 1

- attr(*, "class")= chr "mcmc.list"

  


Such that ..

  





weight_chains



a b s

1 -104.72512 1.0141407  9.369227

2 -104.52297 1.0167432  9.131354

3 -104.72669 1.0139528  9.219877

  



[[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.


Re: [R] Testing for R CMD INSTALL

2021-07-24 Thread Duncan Murdoch

On 24/07/2021 11:22 a.m., Andrew Simmons wrote:

Hello,


I was wondering if anyone has a way to test if a package is currently being
installed. My solution was to check if environment variable "R_INSTALL_PKG"
was unset, something like:

"R CMD INSTALL-ing" <- function ()
!is.na(Sys.getenv("R_INSTALL_PKG", NA))

Unfortunately, I couldn't find what I was looking for with ?"environment
variables". So if anyone has any better methods, I'd be happy to hear them,
thank you!


Normally if you want to execute special code during installation, you'd 
add a Makevars or Makefile to your package and do it there, but 
R_INSTALL_PKG should be defined during a source install.


I believe that no code from the package is executed during a binary 
install:  it just copies files into the appropriate places.


Duncan

__
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] Testing for R CMD INSTALL

2021-07-24 Thread Bert Gunter
Does ?installed.packages help?

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Jul 24, 2021 at 8:30 AM Andrew Simmons  wrote:

> Hello,
>
>
> I was wondering if anyone has a way to test if a package is currently being
> installed. My solution was to check if environment variable "R_INSTALL_PKG"
> was unset, something like:
>
> "R CMD INSTALL-ing" <- function ()
> !is.na(Sys.getenv("R_INSTALL_PKG", NA))
>
> Unfortunately, I couldn't find what I was looking for with ?"environment
> variables". So if anyone has any better methods, I'd be happy to hear them,
> thank you!
>
> [[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] Makefile error

2021-07-24 Thread Ivan Krylov
On Sat, 24 Jul 2021 11:19:41 + (UTC)
Bintao Cui via R-help  wrote:

> Makefile.in:87: *** missing separator.  Stop. 

Thanks for showing us the error message, but this isn't enough
information. In order to be able to help, we also need to know what
exactly you did to get the error message.

See also: http://www.catb.org/~esr/faqs/smart-questions.html

> I am trying to install R-4.1.0 version to fedora

And you're building from source because there doesn't seem to be
R-4.1.0 in the repos? I think you can install R-4.1.0 from Rawhide.

See also: the mailing list about R in Fedora:
https://stat.ethz.ch/mailman/listinfo/r-sig-fedora
This list is about programming in R language, so perhaps your question
would be better addressed there.

-- 
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.


[R] Testing for R CMD INSTALL

2021-07-24 Thread Andrew Simmons
Hello,


I was wondering if anyone has a way to test if a package is currently being
installed. My solution was to check if environment variable "R_INSTALL_PKG"
was unset, something like:

"R CMD INSTALL-ing" <- function ()
!is.na(Sys.getenv("R_INSTALL_PKG", NA))

Unfortunately, I couldn't find what I was looking for with ?"environment
variables". So if anyone has any better methods, I'd be happy to hear them,
thank you!

[[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] Makefile error

2021-07-24 Thread Bintao Cui via R-help
Makefile.in:87: *** missing separator.  Stop. 

I am trying to install R-4.1.0 version to fedora, and got the error above, 
please help!
Thanks.

With regards,Bintao


__
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] Converting a list to a data frame

2021-07-24 Thread Bert Gunter
Here is a reprex that does what I think you want:

ex <- list(mcmc = matrix(1:12, ncol = 3, byrow=TRUE),
   NULL, c("a","b", "s"))

dex <- data.frame(ex$mcmc)
names(dex) <- ex[[3]]

> dex
   a  b  s
1  1  2  3
2  4  5  6
3  7  8  9
4 10 11 12

If this is not correct, you should provide a **plain text** reprex.

Of course, even if correct, this is not a template. The exact process will
depend on the structure of the list.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Jul 24, 2021 at 6:19 AM Jeff Reichman 
wrote:

> How does one convert a list into a data frame?
>
>
>
> > str(weight_chains)
>
> List of 1
>
> $ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...
>
>   ..- attr(*, "dimnames")=List of 2
>
>   .. ..$ : NULL
>
>   .. ..$ : chr [1:3] "a" "b" "s"
>
>   ..- attr(*, "mcpar")= num [1:3] 1001 101000 1
>
> - attr(*, "class")= chr "mcmc.list"
>
>
>
> Such that ..
>
>
>
> >
>
> weight_chains
>
>
>
>a b s
>
> 1 -104.72512 1.0141407  9.369227
>
> 2 -104.52297 1.0167432  9.131354
>
> 3 -104.72669 1.0139528  9.219877
>
>
>
>
> [[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.


[R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
How does one convert a list into a data frame?

 

> str(weight_chains)

List of 1

$ : 'mcmc' num [1:10, 1:3] -105 -105 -105 -104 -103 ...

  ..- attr(*, "dimnames")=List of 2

  .. ..$ : NULL

  .. ..$ : chr [1:3] "a" "b" "s"

  ..- attr(*, "mcpar")= num [1:3] 1001 101000 1

- attr(*, "class")= chr "mcmc.list"

 

Such that ..

 

> 

weight_chains



   a b s  

1 -104.72512 1.0141407  9.369227

2 -104.52297 1.0167432  9.131354

3 -104.72669 1.0139528  9.219877

 


[[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 select rows, not in sequence

2021-07-24 Thread Neha gupta
Thanks a lot Sir, indeed it resolved my issue.

Warm regards

On Sat, Jul 24, 2021 at 1:51 PM Rui Barradas  wrote:

> Hello,
>
> Simply by also passing a vector to the extraction function:
>
>
> rows= df[c(1,2,5,7,12) , ]
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 12:38 de 24/07/21, Neha gupta escreveu:
> > Hi
> >
> > If I have to select specific rows and all columns of a dataframe, I use:
> >
> > rows= df[1:12 , ]
> >
> > However, how to select rows if our required rows are not in sequence i.e.
> > if we need to select row numbers 1,2,5,7, and 12..
> >
> > Warm regards
> >
> >   [[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] How to select rows, not in sequence

2021-07-24 Thread Rui Barradas

Hello,

Simply by also passing a vector to the extraction function:


rows= df[c(1,2,5,7,12) , ]


Hope this helps,

Rui Barradas

Às 12:38 de 24/07/21, Neha gupta escreveu:

Hi

If I have to select specific rows and all columns of a dataframe, I use:

rows= df[1:12 , ]

However, how to select rows if our required rows are not in sequence i.e.
if we need to select row numbers 1,2,5,7, and 12..

Warm regards

[[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] How to select rows, not in sequence

2021-07-24 Thread Neha gupta
Hi

If I have to select specific rows and all columns of a dataframe, I use:

rows= df[1:12 , ]

However, how to select rows if our required rows are not in sequence i.e.
if we need to select row numbers 1,2,5,7, and 12..

Warm regards

[[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.