[R] equal horizontal and vertical proportions in graphics

2013-11-18 Thread Mercutio Florid
I use several different versions of R, including RGui on Windows and rstudio on 
Linux.  In all cases, I use graphical commands, such as image().  

image() displays rectangles, but I want to be able to guarantee that the 
heights of those rectangles will always equal the widths.  Typically, the 
rectangles come out with notable asymmetries.

Thus, if I need to draw a perfect circle with square pixels, I usually get a 
squashed ellipse with oblong pixels.

I have experimented with other commands, and I don't need to continue to use 
image() if some other command would be more suitable.

Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Ben Tupper
Hi,

It's easy, just carry the arguments in '…' forward to where you expect to pass 
them along.


mynumbs<-function(x,y,z=5,...){
 numbs<-sort(sample(y,z, ...))
 for (i in 1:(x-1))
   numbs<-rbind(numbs,sort(sample(y,z, ...)))
 print(numbs)
}

Cheers,
Ben


On Nov 18, 2013, at 8:52 PM, "Lopez, Dan"  wrote:

> Hi R Experts,
> 
> How do you get the ... to work in a user-defined function such as the one I 
> have below?
> For example if I want to pass replace=TRUE to the sample function.
> 
> # This is a sample function that generates x rows of z numbers out of y. 
> Basically a lottery style data set.
> 
> mynumbs<-function(x,y,z=5,...){
>  #x should be a scalar indicating number of rows
>  #y & z are passed to sample function
>  #in the future will add option to output as data.frame instead of matrix
> 
>  numbs<-sort(sample(y,z))
>  for (i in 1:(x-1))
>numbs<-rbind(numbs,sort(sample(y,z)))
>  print(numbs)
> }
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list
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] reshape data frame

2013-11-18 Thread tsippel
Thanks, that seems to work.


On Fri, Nov 15, 2013 at 10:26 PM, arun kirshna [via R] <
ml-node+s789695n4680556...@n4.nabble.com> wrote:

> Hi,
>
> Try:
> var1 <- load("reshape_data.frame.RData")
> ##It is better not to name the objects with function names.
> dat1 <- data
>  reshape1 <- reshape
> names(dat1)[grep("X\\d+",names(dat1))] <-
> gsub("[[:alpha:]]","X_",names(dat1)[grep("X\\d+",names(dat1))])
> res1 <- reshape(dat1,direction="long",varying=7:ncol(dat1),sep="_")
> res2 <- res1[with(res1,order(Yr,Seas,Flt.Svy,Gender,Part,NSAMP)),-9]
> row.names(res2) <- 1:nrow(res2)
> colnames(res2) <- colnames(reshape1)
> all.equal(res2,reshape1)
> #[1] TRUE
>
> A.K.
>
>
> Some advice on transforming my data would be appreciated.  Attached is
> an .Rdata image with my examples (reshape_data.frame.Rdata). Within the
> image are 2 objects:
>
> 1) The "data" object contains an example of my original data
> format. The columns "X20" : "X50" are histogram bins, and the rows
> beneath are the number of observations (ie. counts) within those bins.
> The other columns; "Yr", "Seas", "Flt.Svy", "Gender", "Part", "NSAMP"
> are observation associated with each bin count.
>
> 2) The "reshape" object is the format I need to transform the "data"
> object into.
>
> I think the reshape() function is designed for this, and my
> "data" object is in wide format, and my "resphape" object would be in
> long format.  If indeed reshape() is the best way to do this, I'm
> looking for help in calling the function to transform my data.
>
> Many thanks,
>
> Tim
>
> __
> [hidden email] mailing 
> list
> 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.
>
>
> --
>  If you reply to this email, your message will be added to the discussion
> below:
> http://r.789695.n4.nabble.com/reshape-data-frame-tp4680539p4680556.html
>  To unsubscribe from reshape data frame, click 
> here
> .
> NAML
>




--
View this message in context: 
http://r.789695.n4.nabble.com/reshape-data-frame-tp4680539p4680707.html
Sent from the R help mailing list archive at Nabble.com.
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 convert a 3 dimensional List to make a table with tables tabular()?

2013-11-18 Thread Beckstrand, Janis, NCOD
I have information in a 3 dimensional list that I want to use to create
a table for a written report. 

 

The 3d list was created by applying the epiR function " epitest " to a
list of 8 2x2 tables using  lapply.  

The resulting list gives the 12 statistics with CIs,  that  generated by
epitest, for each of the 8 matrices (i9, i10, etc). 

 

The list has the following form:

 

Statslow$i9

$aprev

est lowerupper

1 0.2263884 0.2244714 0.228314

 

$tprev

   est lower upper

1 0.204388 0.2025413 0.2062442

 

Statslow$i10

$aprev

est lowerupper

1 0.227004 0.22545  0.228314

 

$tprev

   est lower upper

1 0.204388 0.2025413 0.2062442

 

 

I want to create a report that has a table in the following format:

   I9
i10  

 Est   lower upper   Est  lower
upper

 

aprev   0.23 0.22 0.23   etc

tprev0.2   0.20 0.21

etc

 

I have read and tried the tables package pdf and also the information at

http://www.r-statistics.com/tag/data-frame/ about cast() and
tabular.cast_df.r(), 

and also all the information I can find on nested tables, but have not
be successful.  

I have tried to use melt() on the 3D list (to create a dataframe
"statslow.d")  but get what seems more like S3 output :

 

  variable value   L2L1

1  est   0.2263884aprev   i9

2lower0.2244714aprev  i9

3upper   0.2283140aprev   i9

4  est   0.2043880 tprev  i9

5lower0.2025413tprev   i9

6upper   0.2062442tprev   i9

 

When I try to use it with tables() I get errors

and I can't see how to use the tables function on it to get what I want.

Here is the tables() code that I have tried:

 

class(statslow.d)

[1] "data.frame"

> head(statslow.d)

  variable valueL2  L1

1  est 0.2263884 aprev  i9

2lower 0.2244714 aprev i9

3upper 0.2283140 aprev i9

4  est 0.2043880 tprev i9

5lower 0.2025413 tprev i9

6upper 0.2062442 tprev i9

> tabular(statslow.d,L2~L1*variable)

Error in tabular.formula(as.formula(table, env = parent.frame()), ...) :


  data must be a dataframe, list or environment

> statslow.d<-as.data.frame(statslow.d)

> tabular(statslow.d,L2~L1*variable)

Error in tabular.formula(as.formula(table, env = parent.frame()), ...) :


  data must be a dataframe, list or environment

 

I would appreciate any help or hints anyone can give.

 

Jan Beckstrand

 


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Richard M. Heiberger
numbs <- rbind(numbs, sort(sample(y, z, ... )))

See
?Reserved
which sends you to 'Introduction to R'

Rich

On Mon, Nov 18, 2013 at 8:52 PM, Lopez, Dan  wrote:
> Hi R Experts,
>
> How do you get the ... to work in a user-defined function such as the one I 
> have below?
> For example if I want to pass replace=TRUE to the sample function.
>
> # This is a sample function that generates x rows of z numbers out of y. 
> Basically a lottery style data set.
>
> mynumbs<-function(x,y,z=5,...){
>   #x should be a scalar indicating number of rows
>   #y & z are passed to sample function
>   #in the future will add option to output as data.frame instead of matrix
>
>   numbs<-sort(sample(y,z))
>   for (i in 1:(x-1))
> numbs<-rbind(numbs,sort(sample(y,z)))
>   print(numbs)
> }
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> 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
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] find variation of a binary matrix

2013-11-18 Thread email
Hi:

I want to calculate how much the values in a binary matrix varies, and
for that I apply the sd() method.


mat <- matrix(c(1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1), nrow=4, ncol=3)
stddev <- sd(dist(mat,  method="binary"))

And i get the following answer:

stddev
[1] 0.3442652

Is this correct? Or there is a better way out?

Bests:

John

__
R-help@r-project.org mailing list
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] 3D Plot of Convex hull

2013-11-18 Thread wwreith
I have a data set in which I am trying to plot a convex hull in 3 dim. Below
is a subset of the points I would use. Columns 2,3,4 are my x,y,z
coordinates. I found some ways to plot 2D convext hulls or find a convex
hull for higher dimensions, but not how to plot the data. 

I have have attached an example of what I am shooting for in my plot. 

Thanks for the help!

6466574 37 225 27  53.69230 5
6466575 38 225 27  47.54898 5
6466576 39 225 27  58.71439 5
6466577 40 225 27  67.40830 5
6466578 41 225 27  64.40646 5
6466579 42 225 27  71.59792 5
6466580 43 225 27  66.10197 5
6466581 44 225 27  61.53381 5
6466582 45 225 27  69.49900 5
6466583 46 225 27  93.91280 5
6466800 31 226 27 102.78361 5
6466801 32 226 27  69.58787 5
6466802 33 226 27  67.53348 5
6466803 34 226 27  66.83624 5
6466804 35 226 27  52.74981 5
6466805 36 226 27  58.10865 5
6466806 37 226 27  64.29259 5
6466807 38 226 27  55.37983 5
6466808 39 226 27  58.48212 5
6466809 40 226 27  66.21062 5
6466810 41 226 27  58.39149 5
6466811 42 226 27  60.40741 5
6466812 43 226 27  60.95507 5
6466813 44 226 27  64.16653 5
6466814 45 226 27  62.48255 5
6466815 46 226 27  74.37065 5
6466816 47 226 27 100.51262 5 

 



--
View this message in context: 
http://r.789695.n4.nabble.com/3D-Plot-of-Convex-hull-tp4680712.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Lopez, Dan
Thanks Ben.

I feel really dumb. I did enter '...' in my sample function in another version 
of this function. But I just realized I had only done it for the second 
occurrence of the sample function and not the first.

Dan


-Original Message-
From: Ben Tupper [mailto:btup...@bigelow.org] 
Sent: Monday, November 18, 2013 6:00 PM
To: Lopez, Dan
Cc: R help (r-help@r-project.org)
Subject: Re: [R] Passing parameters in a user defined function to another 
function using ...

Hi,

It's easy, just carry the arguments in '...' forward to where you expect to 
pass them along.


mynumbs<-function(x,y,z=5,...){
 numbs<-sort(sample(y,z, ...))
 for (i in 1:(x-1))
   numbs<-rbind(numbs,sort(sample(y,z, ...)))
 print(numbs)
}

Cheers,
Ben


On Nov 18, 2013, at 8:52 PM, "Lopez, Dan"  wrote:

> Hi R Experts,
> 
> How do you get the ... to work in a user-defined function such as the one I 
> have below?
> For example if I want to pass replace=TRUE to the sample function.
> 
> # This is a sample function that generates x rows of z numbers out of y. 
> Basically a lottery style data set.
> 
> mynumbs<-function(x,y,z=5,...){
>  #x should be a scalar indicating number of rows  #y & z are passed to 
> sample function  #in the future will add option to output as 
> data.frame instead of matrix
> 
>  numbs<-sort(sample(y,z))
>  for (i in 1:(x-1))
>numbs<-rbind(numbs,sort(sample(y,z)))
>  print(numbs)
> }
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@r-project.org mailing list
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 can I get seasonal variation table from generalized additive mixed models in R?

2013-11-18 Thread kmmoon100
Hello everyone,

I used a function called gamm in mgcv in R program to investigate seasonal
variation of wind speed based on 13 years of measurement dataset. I would
like to use this variation in my formula for my study but as I am new in R,
it's extremely hard to find values on y-axis.. too many sub-directories of
gamm values make me hard to find what directory was actually used for
y-axis. 
My data set is like this below:

time /day.of.year/ month /day.of.month  /year   / WindSpeed
1   17242000   23.429
2   27252000   29.170
3   37262000   16.813
4   47272000   15.271
5   57282000   10.125
6   67292000   13.938
7   77302000   15.854
8   87312000   10.438
9   981  2000   7.125
. .. ...
. .. ...

As time stamps are separated, I combined all of them first and then ran
additive modelling to look at seasonal and yearly trends of 13 years of wind
data.

My R codes are described below:
ballarat  <- read.csv("ballarat seasonal daily.csv", header=TRUE, sep=",")
ballarat1 <- within(ballarat, Date <- as.Date(paste(year, month,
day.of.month, sep = "-")))

plot(WindSpeed ~ Date, data = ballarat1, type = "l")

mod   <- gamm(WindSpeed ~ s(day.of.year, bs = "cc") + s(time, bs =
"cr"),
 data = ballarat1, method = "REML",
 correlation = corAR1(form = ~ 1 | year),
 knots = list(day.of.year = c(0, 366)))

summary(mod$gam)

plot(mod$gam, pages = 1)


http://i.stack.imgur.com/wU0AU.jpg

>From the link page of trend graphs, You can see that average wind speed has
about +- 2 km/hr variation. I would like to produce tables (two columns
(first column: x axis values, second column: y axis (variations)) each day
of year) of those two graphs. I assume I need to use gam.predict to get
tables of the prediction? As I am new in R, I still can't understand how I
can make it work even after reading description of ?gam.predict function.
Could you please show me how to do it step by step?

Regards,

Kangmin.





--
View this message in context: 
http://r.789695.n4.nabble.com/How-can-I-get-seasonal-variation-table-from-generalized-additive-mixed-models-in-R-tp4680710.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Lopez, Dan
Hi R Experts,

How do you get the ... to work in a user-defined function such as the one I 
have below?
For example if I want to pass replace=TRUE to the sample function.

# This is a sample function that generates x rows of z numbers out of y. 
Basically a lottery style data set.

mynumbs<-function(x,y,z=5,...){
  #x should be a scalar indicating number of rows
  #y & z are passed to sample function
  #in the future will add option to output as data.frame instead of matrix

  numbs<-sort(sample(y,z))
  for (i in 1:(x-1))
numbs<-rbind(numbs,sort(sample(y,z)))
  print(numbs)
}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Reading in csv data with ff package

2013-11-18 Thread Nick McClure
I've spent some time trying to wrap my head around reading in large csv
files with the ff-package.  I think I know how to do it, but am bumping
into some problems.  I've tried to recreate the issues as best as I can
with a smaller example and maybe someone can help explain the problems.

The following code just creates a csv file with an integer column,
character column and logical column.
-
library(ff)
#Create data
size = 2000
fake.data =
data.frame("Integer"=round(10*runif(size)),"Character"=sample(LETTERS,size,replace=T),"Logical"=sample(c(T,F),size,replace=T))

#Write to csv
write.csv(fake.data,"data.csv",row.names=F)
-

Now to read it in as a 'ffdf' class, I can do the following:

-
data = read.csv.ffdf(x=NULL,file="data.csv",nrows=1001,first.rows = 500,
next.rows = 1005,sep=",")
-

That works.  But with my current large data set, read.csv.ffdf is debating
with me about the classes it's importing. I was also messing around with
the first.rows/next.rows, but that's a question for another time. So I'll
try to load the data in, specifying the column types (same exact command,
except with specifying colClasses):

-

> data = read.csv.ffdf(x=NULL,file="data.csv",nrows=1001,first.rows = 500, 
> next.rows = 1005,sep=",",colClasses = c("integer","integer","logical"))Error 
> in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  scan() expected 'an integer', got '"J"'> data =
read.csv.ffdf(x=NULL,file="data.csv",nrows=1001,first.rows = 500,
next.rows = 1005,sep=",",colClasses =
c("integer","character","logical"))Error in ff(initdata = initdata,
length = length, levels = levels, ordered = ordered,  :
  vmode 'character' not implemented> data =
read.csv.ffdf(x=NULL,file="data.csv",nrows=1001,first.rows = 500,
next.rows = 1005,sep=",",colClasses = rep("character",3))Error in
ff(initdata = initdata, length = length, levels = levels, ordered =
ordered,  :
  vmode 'character' not implemented> data =
read.csv.ffdf(x=NULL,file="data.csv",nrows=1001,first.rows = 500,
next.rows = 1005,sep=",",colClasses = rep("raw",3))Error in scan(file,
what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  scan() expected 'a raw', got '8601'

-
I just can't find a combination of classes that will result in this reading
in.  I really don't understand why the classes 'character' won't work for
all of them.  Any thoughts as to why?  I appreciate the help and time.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Setting axis scale for a boxplot

2013-11-18 Thread Jim Lemon

On 11/19/2013 05:57 AM, David Arnold wrote:

Hi,

I have this code:

par(mfrow=c(3,1))

x1=rnorm(10,60,1)
x2=rnorm(10,65,1)
x3=rnorm(10,70,1)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 1")

x1=rnorm(10,60,4)
x2=rnorm(10,65,4)
x3=rnorm(10,70,4)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 2")

x1=rnorm(10,60,9)
x2=rnorm(10,65,9)
x3=rnorm(10,70,9)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 3")

par(mfrow=c(1,1))

How can I set the horizontal axis limits on all three images to be the same
for sake of comparison?


Hi David,
In addition to Bill's answer where you specify limits at the beginning, 
if you want to do it "on the fly" and you are not reusing x1, x2 and x3:


x1a=rnorm(10,60,1)
x2a=rnorm(10,65,1)
x3a=rnorm(10,70,1)
x1b=rnorm(10,60,4)
x2b=rnorm(10,65,4)
x3b=rnorm(10,70,4)
x1c=rnorm(10,60,9)
x2c=rnorm(10,65,9)
x3c=rnorm(10,70,9)
ylim<-range(c(x1a,x2a,x3a,x1b,x2b,x3b,x1c,x2c,x3c))
boxplot(x1a,x2a,x3a,ylim=ylim,horizontal=TRUE,main="Example 1")
boxplot(x1b,x2b,x3b,ylim=ylim,horizontal=TRUE,main="Example 2")
boxplot(x1c,x2c,x3c,ylim=ylim,horizontal=TRUE,main="Example 3")

Jim

__
R-help@r-project.org mailing list
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] Setting axis scale for a boxplot

2013-11-18 Thread William Dunlap
> How can I set the horizontal axis limits on all three images to be the same
> for sake of comparison?

Add ylim=c(dataMin, dataMax) to each call to boxplot(), where
you specify values for dataMin and dataMax so their range is
likely to cover all your data.  ('ylim', not 'xlim' - the horizontal=TRUE
flips the meaning of 'x' and 'y'.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of David Arnold
> Sent: Monday, November 18, 2013 10:58 AM
> To: r-help@r-project.org
> Subject: [R] Setting axis scale for a boxplot
> 
> Hi,
> 
> I have this code:
> 
> par(mfrow=c(3,1))
> 
> x1=rnorm(10,60,1)
> x2=rnorm(10,65,1)
> x3=rnorm(10,70,1)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 1")
> 
> x1=rnorm(10,60,4)
> x2=rnorm(10,65,4)
> x3=rnorm(10,70,4)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 2")
> 
> x1=rnorm(10,60,9)
> x2=rnorm(10,65,9)
> x3=rnorm(10,70,9)
> boxplot(x1,x2,x3,horizontal=TRUE,main="Example 3")
> 
> par(mfrow=c(1,1))
> 
> How can I set the horizontal axis limits on all three images to be the same
> for sake of comparison?
> 
> D.
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Setting-axis-scale-for-a-
> boxplot-tp4680704.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> 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
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] Setting axis scale for a boxplot

2013-11-18 Thread David Arnold
Hi,

I have this code:

par(mfrow=c(3,1))

x1=rnorm(10,60,1)
x2=rnorm(10,65,1)
x3=rnorm(10,70,1)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 1")

x1=rnorm(10,60,4)
x2=rnorm(10,65,4)
x3=rnorm(10,70,4)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 2")

x1=rnorm(10,60,9)
x2=rnorm(10,65,9)
x3=rnorm(10,70,9)
boxplot(x1,x2,x3,horizontal=TRUE,main="Example 3")

par(mfrow=c(1,1))

How can I set the horizontal axis limits on all three images to be the same
for sake of comparison?

D.



--
View this message in context: 
http://r.789695.n4.nabble.com/Setting-axis-scale-for-a-boxplot-tp4680704.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Jeff Newmiller
No, sorry to flog a dead horse, but you do not appear to get it yet and you 
really should understand this concept.  The minimal reproducible example would 
have been R code that we could run that generated an email that you think 
should have the matrix in it, but does not. In practically all help queries on 
this list we should be able to run your code and see the not-desired behavior.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Ira Fuchs  wrote:
>I understand what you are saying. I just didn't think that showing a
>sendmailR with a matrix as the body of the message would have been very
>helpful since it is the fact that the received email has no content
>that is the problem and that would not have shown up in the R console
>output. 
>On Nov 18, 2013, at 10:47 AM, Jeff Newmiller wrote:
>
>> You provided examples of what you wanted, but not examples where the
>same code in a different context failed to provide the result you
>wanted. "Reproducible" means "reproduces the problem".
>>
>---
>> Jeff NewmillerThe .   .  Go
>Live...
>> DCN:Basics: ##.#.   ##.#.  Live
>Go...
>>  Live:   OO#.. Dead: OO#.. 
>Playing
>> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>> /Software/Embedded Controllers)   .OO#.   .OO#. 
>rocks...1k
>>
>---
>
>> Sent from my phone. Please excuse my brevity.
>> 
>> Ira Fuchs  wrote:
>>> I thought that I had provided an example of what I wanted to do but
>in
>>> any case, capture.output seems to work, as in
>>> 
>>> sendmailR(to,from, capture.output(matrix_to_send))
>>> 
>>> I'm sure that there are myriad other ways (I tried print, which is
>>> mentioned in FAQ 7.16 but it doesn't work in this context)
>>> 
>>> Thanks for your help.
>>> On Nov 18, 2013, at 10:04 AM, Jeff Newmiller wrote:
>>> 
 You have not provided the minimal reproducible code that the footer
>>> of this email asks for, so we are playing 20 questions.
 
 Perhaps you should convert the matrix to a data frame? Or is this
>an
>>> example of FAQ 7.16?
 
>>>
>---
 Jeff NewmillerThe .   .  Go
>>> Live...
 DCN:Basics: ##.#.   ##.#. 
>Live
>>> Go...
 Live:   OO#.. Dead: OO#.. 
>>> Playing
 Research Engineer (Solar/BatteriesO.O#.   #.O#. 
>with
 /Software/Embedded Controllers)   .OO#.   .OO#. 
>>> rocks...1k
 
>>>
>---
>>> 
 Sent from my phone. Please excuse my brevity.
 
 Ira Fuchs  wrote:
> Thanks for the suggestion. I just tried dput and it did not
>produce
> what sendmailR requires for the body parameter. Here is a
>simplified
> version of what I need to do:
> 
>> x=matrix(c(1,2,3),1,3)
>> x
>   [,1] [,2] [,3]
> [1,]123
>> colnames(x)=c("a","b","c")
>> x
>   a b c
> [1,] 1 2 3
> 
>> dput(x)
> structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
>  c("a", "b", "c")))
> 
> I want to send x in sendmailR(to,from,x) and have it look more or
>>> less
> like the output above. Simple, right?
> 
> 
> On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
> 
>> What about dput()?
>> 
>> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs 
> wrote:
>>> I have a matrix which has colnames and I would like to send this
> matrix using sendmailR. How can I convert this simple matrix to a
> format which can be used as the body variable in sendmailR? I see
>>> how I
> can create a file attachment using mime_part but I would like to
>>> send
> the matrix in the body of the email.
>>> 
>>> The matrix looks like:
>>> 
>>>ABD  DEF  GHI  JKL MNO   TOT
>>> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>>> 
>>> 
>>> All the conversions I have tried end up sending the matrix
>without
> the colnames.
>>> 
>>> Thanks.
>>> 
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>

[R] multilevel sampling weight

2013-11-18 Thread Pablo Menese Camargo
Anyone is working with the upgrade of any multilevel package for apply
sampling weights?

Thanks

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] quotation marks and scan

2013-11-18 Thread MacQueen, Don
I know you have a solution, but I would have suggested using print() with
quote=FALSE as a better way to illuminate what is going on, as in this
example:

> foo <- 'bah"bah'
> foo
[1] "bah\"bah"
> print(foo)
[1] "bah\"bah"
> print(foo, quote=FALSE)
[1] bah"bah

As others said, the backslash isn't really there. So you only have to get
rid of the " which you can do with
> gsub('"','',foo)
[1] "bahbah"



To summarize, in R, due to its rules for formatting printed output, what
you see isn't always exactly what you have, and this is an example.

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 11/17/13 2:07 PM, "Erin Hodgess"  wrote:

>Dear R People:
>
>I'm sure that this is a very simple problem, but I have been wresting with
>it for some time.
>
>I have the following file that has the following one line:
>
> CRS("+init=epsg:28992")
>
>Fair enough.  I scan it into R and get the following:
>
>> u
>[1] "CRS(\"+init=epsg:28992\")"
>> gsub(pattern='\"',replacement='"',x=u)
>[1] "CRS(\"+init=epsg:28992\")"
>
>I need to get rid of the extra quotation marks and slashes.  I've tried
>all
>sorts of things, including gsub, as you see,  but no good.
>
>Thank you for any help.
>
>Sincerely,
>Erin
>
>
>-- 
>Erin Hodgess
>Associate Professor
>Department of Computer and Mathematical Sciences
>University of Houston - Downtown
>mailto: erinm.hodg...@gmail.com
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list
>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
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] Sending a matrix in an email

2013-11-18 Thread Ira Fuchs
I understand what you are saying. I just didn't think that showing a sendmailR 
with a matrix as the body of the message would have been very helpful since it 
is the fact that the received email has no content that is the problem and that 
would not have shown up in the R console output. 
On Nov 18, 2013, at 10:47 AM, Jeff Newmiller wrote:

> You provided examples of what you wanted, but not examples where the same 
> code in a different context failed to provide the result you wanted. 
> "Reproducible" means "reproduces the problem".
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>  Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> --- 
> Sent from my phone. Please excuse my brevity.
> 
> Ira Fuchs  wrote:
>> I thought that I had provided an example of what I wanted to do but in
>> any case, capture.output seems to work, as in
>> 
>> sendmailR(to,from, capture.output(matrix_to_send))
>> 
>> I'm sure that there are myriad other ways (I tried print, which is
>> mentioned in FAQ 7.16 but it doesn't work in this context)
>> 
>> Thanks for your help.
>> On Nov 18, 2013, at 10:04 AM, Jeff Newmiller wrote:
>> 
>>> You have not provided the minimal reproducible code that the footer
>> of this email asks for, so we are playing 20 questions.
>>> 
>>> Perhaps you should convert the matrix to a data frame? Or is this an
>> example of FAQ 7.16?
>>> 
>> ---
>>> Jeff NewmillerThe .   .  Go
>> Live...
>>> DCN:Basics: ##.#.   ##.#.  Live
>> Go...
>>> Live:   OO#.. Dead: OO#.. 
>> Playing
>>> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>>> /Software/Embedded Controllers)   .OO#.   .OO#. 
>> rocks...1k
>>> 
>> ---
>> 
>>> Sent from my phone. Please excuse my brevity.
>>> 
>>> Ira Fuchs  wrote:
 Thanks for the suggestion. I just tried dput and it did not produce
 what sendmailR requires for the body parameter. Here is a simplified
 version of what I need to do:
 
> x=matrix(c(1,2,3),1,3)
> x
   [,1] [,2] [,3]
 [1,]123
> colnames(x)=c("a","b","c")
> x
   a b c
 [1,] 1 2 3
 
> dput(x)
 structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
  c("a", "b", "c")))
 
 I want to send x in sendmailR(to,from,x) and have it look more or
>> less
 like the output above. Simple, right?
 
 
 On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
 
> What about dput()?
> 
> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs 
 wrote:
>> I have a matrix which has colnames and I would like to send this
 matrix using sendmailR. How can I convert this simple matrix to a
 format which can be used as the body variable in sendmailR? I see
>> how I
 can create a file attachment using mime_part but I would like to
>> send
 the matrix in the body of the email.
>> 
>> The matrix looks like:
>> 
>>ABD  DEF  GHI  JKL MNO   TOT
>> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>> 
>> 
>> All the conversions I have tried end up sending the matrix without
 the colnames.
>> 
>> Thanks.
>> 
 
 __
 R-help@r-project.org mailing list
 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
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] Sending a matrix in an email

2013-11-18 Thread Jeff Newmiller
You provided examples of what you wanted, but not examples where the same code 
in a different context failed to provide the result you wanted. "Reproducible" 
means "reproduces the problem".
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Ira Fuchs  wrote:
>I thought that I had provided an example of what I wanted to do but in
>any case, capture.output seems to work, as in
>
>sendmailR(to,from, capture.output(matrix_to_send))
>
>I'm sure that there are myriad other ways (I tried print, which is
>mentioned in FAQ 7.16 but it doesn't work in this context)
>
>Thanks for your help.
>On Nov 18, 2013, at 10:04 AM, Jeff Newmiller wrote:
>
>> You have not provided the minimal reproducible code that the footer
>of this email asks for, so we are playing 20 questions.
>> 
>> Perhaps you should convert the matrix to a data frame? Or is this an
>example of FAQ 7.16?
>>
>---
>> Jeff NewmillerThe .   .  Go
>Live...
>> DCN:Basics: ##.#.   ##.#.  Live
>Go...
>>  Live:   OO#.. Dead: OO#.. 
>Playing
>> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
>> /Software/Embedded Controllers)   .OO#.   .OO#. 
>rocks...1k
>>
>---
>
>> Sent from my phone. Please excuse my brevity.
>> 
>> Ira Fuchs  wrote:
>>> Thanks for the suggestion. I just tried dput and it did not produce
>>> what sendmailR requires for the body parameter. Here is a simplified
>>> version of what I need to do:
>>> 
 x=matrix(c(1,2,3),1,3)
 x
>>>[,1] [,2] [,3]
>>> [1,]123
 colnames(x)=c("a","b","c")
 x
>>>a b c
>>> [1,] 1 2 3
>>> 
 dput(x)
>>> structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
>>>   c("a", "b", "c")))
>>> 
>>> I want to send x in sendmailR(to,from,x) and have it look more or
>less
>>> like the output above. Simple, right?
>>> 
>>> 
>>> On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
>>> 
 What about dput()?
 
 On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs 
>>> wrote:
> I have a matrix which has colnames and I would like to send this
>>> matrix using sendmailR. How can I convert this simple matrix to a
>>> format which can be used as the body variable in sendmailR? I see
>how I
>>> can create a file attachment using mime_part but I would like to
>send
>>> the matrix in the body of the email.
> 
> The matrix looks like:
> 
> ABD  DEF  GHI  JKL MNO   TOT
> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
> 
> 
> All the conversions I have tried end up sending the matrix without
>>> the colnames.
> 
> Thanks.
> 
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> 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
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] Rotation of parallel lines

2013-11-18 Thread Carl Witthoft
See my answer at Stack Overflow -- repeated here for anyone else who wants a
trivial function.
# coordinate transform: cartesian plane rotation
xyrot<-function(pairs,ang){
# pairs must be Nx2 matrix w/ x in first column and y in second
xrot <- pairs[,1]*cos(ang) - pairs[,2]*sin(ang)
yrot <- pairs[,1]*sin(ang) + pairs[,2]*cos(ang)
return(invisible(cbind(xrot,yrot)))
}


tonio wrote
> Dear list, 
> 
> Consider these two parallel segments in a plot.
> 
> plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
> segments(1, 1, 6, 1)
> segments(1, 3, 6, 3)
> 
> 
> 
> How can I rotate the two lines together by a defined angle?
> 
> 
> Thank you all in advance.
> 
> Best,
> Antonio
> 
> 
> 
> Antonio Rivero Ostoic
> Assistant professor, PhD
> 
> AARHUS UNIVERSITY
> School of Business and Social Science
> Quantitative Analytics Group and Cognition and Behaviour Lab
> Bartholins Allé 10 
> DK-8000 Aarhus C
> 
> T: +45 871 65421
> M: 

> jari@

> 
> 
> __

> R-help@

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





--
View this message in context: 
http://r.789695.n4.nabble.com/Rotation-of-parallel-lines-tp4680676p4680695.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Ira Fuchs
I thought that I had provided an example of what I wanted to do but in any 
case, capture.output seems to work, as in

sendmailR(to,from, capture.output(matrix_to_send))

I'm sure that there are myriad other ways (I tried print, which is mentioned in 
FAQ 7.16 but it doesn't work in this context)

Thanks for your help.
On Nov 18, 2013, at 10:04 AM, Jeff Newmiller wrote:

> You have not provided the minimal reproducible code that the footer of this 
> email asks for, so we are playing 20 questions.
> 
> Perhaps you should convert the matrix to a data frame? Or is this an example 
> of FAQ 7.16?
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>  Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> --- 
> Sent from my phone. Please excuse my brevity.
> 
> Ira Fuchs  wrote:
>> Thanks for the suggestion. I just tried dput and it did not produce
>> what sendmailR requires for the body parameter. Here is a simplified
>> version of what I need to do:
>> 
>>> x=matrix(c(1,2,3),1,3)
>>> x
>>[,1] [,2] [,3]
>> [1,]123
>>> colnames(x)=c("a","b","c")
>>> x
>>a b c
>> [1,] 1 2 3
>> 
>>> dput(x)
>> structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
>>   c("a", "b", "c")))
>> 
>> I want to send x in sendmailR(to,from,x) and have it look more or less
>> like the output above. Simple, right?
>> 
>> 
>> On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
>> 
>>> What about dput()?
>>> 
>>> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs 
>> wrote:
 I have a matrix which has colnames and I would like to send this
>> matrix using sendmailR. How can I convert this simple matrix to a
>> format which can be used as the body variable in sendmailR? I see how I
>> can create a file attachment using mime_part but I would like to send
>> the matrix in the body of the email.
 
 The matrix looks like:
 
 ABD  DEF  GHI  JKL MNO   TOT
 [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
 
 
 All the conversions I have tried end up sending the matrix without
>> the colnames.
 
 Thanks.
 
>> 
>> __
>> R-help@r-project.org mailing list
>> 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
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] creating upper triangular matrix

2013-11-18 Thread Carl Witthoft
OK, I'm pre-coffee, but what's wrong with using upper.tri to create a new
matrix and then multiplying that matrix by the original "dat" matrix (direct
multiplication, not matrix multiply) to get the desired answer?


Bert Gunter wrote
> I believe matrix indexing makes Arun's complex code wholly unnececessary:
> 
> Starting with dat1 as above:
> 
> m <- matrix(0,4,4)
> m[as.matrix(dat1[,1:2])] <- dat1[,3]
> 
> ## yielding:
> m
> 
>  [,1] [,2] [,3] [,4]
> [1,]0211
> [2,]0121
> [3,]0002
> [4,]0000
> 
> If you want to get rid of any nonzero diagonal entries:
> 
> diag(m) <- 0 ## does it.
> 
> Cheers,
> Bert
> 
> 
> 
> 
> 
> On Sun, Nov 17, 2013 at 10:27 AM, arun <

> smartpink111@

> > wrote:
>> Hi,
>> May be this helps:
>>
>> dat1 <- read.table(text="
>> data data freq
>> 1   2 2
>> 1   3 1
>> 1   4 1
>> 2   3 2
>> 2   4 1
>> 2   2 1
>> 3  4   2",sep="",header=TRUE)
>> val<- unique(c(dat1[,1],dat1[,2]))
>> dat2 <-expand.grid(data=val,data.1=val)
>> library(plyr)
>> library(reshape2)
>> res <- dcast(join(dat2,dat1),data~data.1,value.var="freq",fill=0)
>> row.names(res) <- res[,1]
>> res1 <- as.matrix(res[,-1])
>> diag(res1) <-0
>>
>> #or
>>  m1 <- matrix(0,length(val),length(val),dimnames=list(val,val))
>>
>>  indx1 <- outer(colnames(m1),rownames(m1),paste,sep="")
>>  indx2 <- paste0(dat1[,1],dat1[,2])
>> m1[match(indx2,indx1)] <- dat1[,3]
>>  diag(m1) <- 0
>>  m1
>> #  1 2 3 4
>> #1 0 2 1 1
>> #2 0 0 2 1
>> #3 0 0 0 2
>> #4 0 0 0 0
>>
>> A.K.
>>
>>
>> Hello ,
>> I am working on a project ,
>> i need to create an upper triangular matrix from the data in this form;
>> data data freq
>> 1   2 2
>> 1   3 1
>> 1   4 1
>> 2   3 2
>> 2   4 1
>> 2   2 1
>> 3  4   2
>>
>>  to a triangular matrix in the following form :
>>  1   23   4
>> 10  21   1
>> 20  02   1
>> 30  00   2
>> 40  00   0
>>
>> i am new to R please help
>>
>>
>> __
>> 

> R-help@

>  mailing list
>> 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.
> 
> 
> 
> -- 
> 
> Bert Gunter
> Genentech Nonclinical Biostatistics
> 
> (650) 467-7374
> 
> __

> R-help@

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





--
View this message in context: 
http://r.789695.n4.nabble.com/creating-upper-triangular-matrix-tp4680632p4680674.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Jeff Newmiller
You have not provided the minimal reproducible code that the footer of this 
email asks for, so we are playing 20 questions.

Perhaps you should convert the matrix to a data frame? Or is this an example of 
FAQ 7.16?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Ira Fuchs  wrote:
>Thanks for the suggestion. I just tried dput and it did not produce
>what sendmailR requires for the body parameter. Here is a simplified
>version of what I need to do:
>
>> x=matrix(c(1,2,3),1,3)
>> x
> [,1] [,2] [,3]
>[1,]123
>> colnames(x)=c("a","b","c")
>> x
> a b c
>[1,] 1 2 3
>
>> dput(x)
>structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
>c("a", "b", "c")))
>
>I want to send x in sendmailR(to,from,x) and have it look more or less
>like the output above. Simple, right?
>
>
>On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
>
>> What about dput()?
>> 
>> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs 
>wrote:
>>> I have a matrix which has colnames and I would like to send this
>matrix using sendmailR. How can I convert this simple matrix to a
>format which can be used as the body variable in sendmailR? I see how I
>can create a file attachment using mime_part but I would like to send
>the matrix in the body of the email.
>>> 
>>> The matrix looks like:
>>> 
>>>  ABD  DEF  GHI  JKL MNO   TOT
>>> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>>> 
>>> 
>>> All the conversions I have tried end up sending the matrix without
>the colnames.
>>> 
>>> Thanks.
>>> 
>
>__
>R-help@r-project.org mailing list
>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
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] Sending a matrix in an email

2013-11-18 Thread Carl Witthoft
I think it'd be easier and safer to save the matrix, either as an .Rdata
binary or as a text file, zip that file, and use the sendmailR tools to
attach the file to your message.


Fuchs Ira-3 wrote
> I have a matrix which has colnames and I would like to send this matrix
> using sendmailR. How can I convert this simple matrix to a format which
> can be used as the body variable in sendmailR? I see how I can create a
> file attachment using mime_part but I would like to send the matrix in the
> body of the email. 
> 
> The matrix looks like:
> 
>   ABD  DEF  GHI  JKL MNO   TOT 
> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
> 
> All the conversions I have tried end up sending the matrix without the
> colnames.
> 
> Thanks.
> 
> 
>   [[alternative HTML version deleted]]
> 
> __

> R-help@

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





--
View this message in context: 
http://r.789695.n4.nabble.com/Sending-a-matrix-in-an-email-tp4680663p4680675.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Ira Fuchs
That's the ticket!  So many functions…so little time.  Thanks to everyone.
On Nov 18, 2013, at 9:47 AM, David Winsemius wrote:

> 
> On Nov 18, 2013, at 8:30 AM, Ira Fuchs wrote:
> 
>> Thanks for the suggestion. I just tried dput and it did not produce what 
>> sendmailR requires for the body parameter. Here is a simplified version of 
>> what I need to do:
>> 
>>> x=matrix(c(1,2,3),1,3)
>>> x
>>[,1] [,2] [,3]
>> [1,]123
>>> colnames(x)=c("a","b","c")
>>> x
>>a b c
>> [1,] 1 2 3
>> 
>>> dput(x)
>> structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL,
>>   c("a", "b", "c")))
>> 
>> I want to send x in sendmailR(to,from,x) and have it look more or less like 
>> the output above. Simple, right?
> 
> After this at the console:
> 
> sink("myfile.txt")
> > x=matrix(c(1,2,3),1,3)
> > x
> > colnames(x)=c("a","b","c")
> > x
> > sink()
> 
> I get this in myfile.txt:
> 
> [,1] [,2] [,3]
> [1,]123
> a b c
> [1,] 1 2 3
> 
> There is also a capture.output function.
> 
> -- 
> David
> 
>> 
>> 
>> On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:
>> 
>>> What about dput()?
>>> 
>>> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs  wrote:
 I have a matrix which has colnames and I would like to send this matrix 
 using sendmailR. How can I convert this simple matrix to a format which 
 can be used as the body variable in sendmailR? I see how I can create a 
 file attachment using mime_part but I would like to send the matrix in the 
 body of the email.
 
 The matrix looks like:
 
ABD  DEF  GHI  JKL MNO   TOT
 [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
 
 
 All the conversions I have tried end up sending the matrix without the 
 colnames.
 
 Thanks.
 
>> 
>> __
>> R-help@r-project.org mailing list
>> 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.
> 
> David Winsemius, MD
> Alameda, CA, USA
> 

__
R-help@r-project.org mailing list
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] Tukey test for anavo split by multiples factors

2013-11-18 Thread catalin roibu
Hello all!
I have a problem with Anova in R and I don't know how to solve that. I want
to compute Anova for each experiment (exp). I use this code:

test<-lapply(split(eg,eg$Exp),function(x) aov(masa.uscat.tr ~ Clona,data =
x))
or
test<-by(eg,eg$Exp, function(x) aov(masa.uscat.tr~Clona,data=x))

I try to compute Tukey HSD test for all Anova for each experiments (Exp)
and I want to evaluate model Effects of Anova for each experiment.

This are my big problems.

thank you!

Thank you very much!

My data is like this:



Exp Plot Clona Prov masa uscat tr masa usc. Ram masa usc total
B 36 Max4 P Puieti 6.199848485 2.639325843 8.839174328
B 36 Max4 P Puieti 3.87875 1.4798 5.35855
B 36 Max4 P Puieti 7.822702703 3.32852071 11.15122341
B 36 Max4 P Puieti 5.645384615 1.995238095 7.640622711
B 36 Max4 P Puieti 10.2 3.514864865 13.71486486
B 36 Max4 P Puieti 8.815545455 3.35627907 12.17182452
B 36 Max4 P Puieti 5.0 1.607142857 6.64047619
B 36 Max4 P Puieti 6.693488372 2.630208333 9.323696705
B 36 Max4 P Puieti 6.021012658 1.60293578 7.623948438
B 36 Max4 P Puieti 10.20582524 3.768314607 13.97413985
B 33 Max4 Butasi 5.899417476 1.745394737 7.644812213
B 33 Max4 Butasi 3.261428571 1.335735294 4.597163866
B 33 Max4 Butasi 3.359508197 1.456641221 4.816149418
B 33 Max4 Butasi 5.036363636 2.097793103 7.13415674
B 33 Max4 Butasi 3.122162162 1.612012579 4.734174741
B 33 Max4 Butasi 5.042474227 3.246916427 8.289390653
B 33 Max4 Butasi 5.058255814 2.724299065 7.782554879
B 33 Max4 Butasi 4.977818182 1.713504274 6.691322455
B 33 Max4 Butasi 3.195294118 1.243411765 4.438705882
B 33 Max4 Butasi 1.831818182 1.009090909 2.840909091
B 30 AF2 Butasi 6.98195122 1.764 8.74595122
B 30 AF2 Butasi 5.85833 1.686623377 7.54495671
B 30 AF2 Butasi 10.625 3.04 13.665
C 39 AF6 Sade 10.27125 2.283193277 12.55444328
C 39 AF6 Sade 9.473488372 1.909414414 11.38290279
C 39 AF6 Sade 10.4825 2 12.4825
C 39 AF6 Sade 11.61579545 2.431136364 14.04693182
C 39 AF6 Sade 8.185074627 1.80933 9.99440796
C 39 AF6 Sade 11.04510638 2.23672956 13.28183594
C 39 AF6 Sade 9.06667 2.473785714 11.54045238
C 39 AF6 Sade 10.12787611 3.097631579 13.22550769
C 39 AF6 Sade 9.171290323 1.821226415 10.99251674
C 39 AF6 Sade 12.1846875 2.262590361 14.44727786
C 42 Pannonia Sade 9.275 2.482173913 11.75717391
C 42 Pannonia Sade 7.21 1.77 8.98
C 42 Pannonia Sade 11.36939394 3.111780822 14.48117476
C 42 Pannonia Sade 7.85296875 1.943475177 9.796443927
C 42 Pannonia Sade 8.25 2.54047619 10.79047619
C 42 Pannonia Sade 8.669277108 2.187071429 10.85634854
C 42 Pannonia Sade 8.510886076 2.05344 10.56432608
C 42 Pannonia Sade 9.36222 5.525531915 14.88775414
C 42 Pannonia Sade 11.08481928 2.573193277 13.65801255
C 42 Pannonia Sade 10.17462687 3.003225806 13.17785267
C 45 Monviso Sade 12.99693878 3.216083916 16.21302269
C 45 Monviso Sade 11.11456522 1.885714286 13.0002795
C 45 Monviso Sade 8.12933 1.53267 9.662
C 45 Monviso Sade 9.943043478 2.38300885 12.32605233
C 45 Monviso Sade 11.9805814 3.080923913 15.06150531
C 45 Monviso Sade 10.31376623 2.210526316 12.52429255
C 45 Monviso Sade 9.947586207 1.86083 11.80841954
C 45 Monviso Sade 12.24261538 2.166857143 14.40947253
C 45 Monviso Sade 13.56650602 2.414371257 15.98087728
C 45 Monviso Sade 10.87574257 2.922340426 13.798083
C 48 AF2 Sade 9.334545455 2.201822917 11.53636837
C 48 AF2 Sade 9.747640449 2.811780822 12.55942127
C 48 AF2 Sade 14.29541284 4.506885246 18.80229809
C 48 AF2 Sade 10.26451613 3.014322581 13.27883871
C 48 AF2 Sade 13.30924242 3.960661765 17.26990419
C 48 AF2 Sade 13.23228426 5.00546875 18.23775301
C 48 AF2 Sade 14.8277027 4.450447761 19.27815046
C 48 AF2 Sade 15.23669528 7.559322034 22.79601731
C 48 AF2 Sade 13.27198582 3.758252427 17.03023824
C 48 AF2 Sade 13.7136 5.69044 19.40408889
C 51 Max4 Sade 8.860884956 5.613586957 14.47447191
C 51 Max4 Sade 13.29153285 5.653061224 18.94459407
C 51 Max4 Sade 9.609850746 3.385714286 12.99556503

-- 
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
   +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread David Winsemius


On Nov 18, 2013, at 8:30 AM, Ira Fuchs wrote:

Thanks for the suggestion. I just tried dput and it did not produce  
what sendmailR requires for the body parameter. Here is a simplified  
version of what I need to do:



x=matrix(c(1,2,3),1,3)
x

[,1] [,2] [,3]
[1,]123

colnames(x)=c("a","b","c")
x

a b c
[1,] 1 2 3


dput(x)

structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL,
   c("a", "b", "c")))

I want to send x in sendmailR(to,from,x) and have it look more or  
less like the output above. Simple, right?


After this at the console:

sink("myfile.txt")
> x=matrix(c(1,2,3),1,3)
> x
> colnames(x)=c("a","b","c")
> x
> sink()

I get this in myfile.txt:

 [,1] [,2] [,3]
[1,]123
 a b c
[1,] 1 2 3

There is also a capture.output function.

--
David




On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:


What about dput()?

On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs   
wrote:
I have a matrix which has colnames and I would like to send this  
matrix using sendmailR. How can I convert this simple matrix to a  
format which can be used as the body variable in sendmailR? I see  
how I can create a file attachment using mime_part but I would  
like to send the matrix in the body of the email.


The matrix looks like:

ABD  DEF  GHI  JKL MNO   TOT
[1,] 0.44 0.81 1.67 0.37 0.31 -1.18


All the conversions I have tried end up sending the matrix without  
the colnames.


Thanks.



__
R-help@r-project.org mailing list
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.


David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
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] Extract values from vector and repeat by group

2013-11-18 Thread arun
Hi,

I would also add an index to make it work for groups that doesn't have time=4.
df1 <- df[-12,]
fun1 <- function(dat,n) {
 indx <- with(dat,tapply(time==n,group,FUN=any))
 indx2 <- with(dat,ave(time==n,group,FUN=any))
 dat[indx2,"new"] <- rep(dat$var[dat$time==n],rle(dat$group)$lengths[indx])
dat[!is.na(dat$new),] 
 }
fun1(df,4)
fun1(df1,4)

A.K.




On Monday, November 18, 2013 9:18 AM, PIKAL Petr  wrote:
Hi

probably not most elegant and also not general but

rep(df$var[df$time==4],rle(df$group)$lengths)

or

rep(df$var[df$time==4],  sapply(split(df$var,df$group), length))

shall give you desired vector.

Regards
Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Benjamin Gillespie
> Sent: Sunday, November 17, 2013 3:47 PM
> To: r-help@r-project.org
> Subject: [R] Extract values from vector and repeat by group
> 
> Hi all,
> 
> I hope you can help.
> 
> I have a data frame 'df':
> 
> group=c(rep(1,8),rep(2,10),rep(3,11))
> var=rnorm(29)
> time=c(seq(1,8),seq(1,10),seq(1,11))
> df=data.frame(group,var,time)
> 
> I would like to extract the value from 'var' for each 'group' at
> 'time'=4 and repeat these extracted values in a new vector ('new') n
> times where n is the number of rows for each group. I did this by hand
> as below, but there must be a quicker way:
> 
> subset=subset(df,df$time==4)
> subset
> group        var time
> 4      1  0.2531270    4
> 12     2 -0.3600128    4
> 22     3  0.4194730    4
> 
> df$new=c(rep(0.2531270,8),rep(-0.3600128,10),rep(0.4194730,11))
> 
> Any questions please ask,
> 
> Many thanks in advance,
> 
> Ben Gillespie, Research Postgraduate
> o---o
> School of Geography, University of Leeds, Leeds, LS2 9JT o-
> --o
> Tel: +44(0)113 34 33345
> Mob: +44(0)770 868 7641
> o---o
> http://www.geog.leeds.ac.uk/
> o-o
> @RiversBenG
> o--o
> __
> R-help@r-project.org mailing list
> 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
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
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] Providing a Title for a Write.Table - Thinking of Titles in SPSS CTABLES

2013-11-18 Thread Zach Feinstein
I understand how I may use message() to provide some output on which run I will 
be looking at. However, I wish to automate it, and have it written out to a 
tab-delimited file. Below is the command to output my coefficients:

write.table(zbetas, file = "z_coeffs.csv", sep="\t", append = TRUE)

I do this run multiple times. It appends the latter results to the end of my 
.csv file.

Is there a way to say just before the write.table something to the effect of:

title("First Run", append = TRUE)?

Or perhaps there is a sub-command in the write.table to accomplish this.

So when I interactively run my code it could be something like:

First run
Coeff1 0.34
Coeff2 0.96

Second run
Coeff1 0.47
Coeff2 0.95

Thank you very much in advance.

Zach Feinstein
zfeinst...@isgmn.com
(952) 277-0162
(612) 590-4813 (mobile)


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] issues with calling predict.coxph.penal (survival) inside a function

2013-11-18 Thread julian.bothe
Hello,
and thanks for the answer.

1) I found a work-around - in  the end it is easier than thought before.
The only thing you have to do is to have the same variable name with the
new values.
So if predict(coxph.penal.fit, newdata[subset,]) does not work inside a
function,  the following works:

pred_function <- function(coxph_model, newdata){
#things to do before
newdata=newdata[the_subset_i_want,]
predict(coxph_model, newdata)

}

I attach a working example.

I am not sure, maybe this is even what is written in the help to
NextMethod ;)
" NextMethod works by creating a special call frame for the next method.
If no new arguments are supplied, the arguments will be the same in
number, order and name as those to the current method but their values
will be promises to evaluate their name in the current method and
environment. Any named arguments matched to ... are handled specially:
they either replace existing arguments of the same name or are appended to
the argument list. They are passed on as the promise that was supplied as
an argument to the current environment. (S does this differently!) *If
they have been evaluated in the current (or a previous environment) they
remain evaluated.* (This is a complex area, and subject to change: see the
draft ‘R Language Definition’.)" (Help to NextMethod )

2) Terry, I am not sure about the work-around you provided in your mail. I
want to do subsetting on newdata, not on the model.
Additionally, when trying the example you provided, I received different
results. Example is attached.

Thanks and all the best
Julian

#---

test1 <- data.frame(time=c(4,3,1,1,2,2,3),
  status=c(1,1,1,0,1,1,0),
  x=c(0,2,1,1,1,0,0),
  sex=c(0,0,0,0,1,1,1))

# Fit a stratified model
fit1 <- coxph(Surv(time, status) ~ x + strata(sex), test1)
summary(fit1)

#fit stratified wih spline
fit2 <- coxph(Surv(time, status) ~ pspline(x, df=2) + strata(sex), test1)
summary(fit2)

## work-around
predicting_function_which_works<- function(model, newdata ){
  subs <-vector(mode='logical', length=nrow(newdata))
  subs[3:length(subs)]<- TRUE #try with first values set to false

  newdata_alt<-newdata
  newdata<-newdata[subs,]

  ret<-vector(mode='numeric', length=nrow(newdata_alt))
  ret[!subs]<- NA
  ret[subs]<- predict(model,newdata )
  return(ret)
}

predicting_function_which_works(fit1, test1) # works

predicting_function_which_works(fit2,test1)  # works
predicting_function_which_works(fit2,data.frame(time=c(4,3,1,1,2), # works
  status=c(1,1,1,0,1),
  x=c(0,2,1,1,2),
  sex=c(1,1,0,0,1))
)

## How I understood Terry's work-around. Provides different results and
doesn't consider subset

predicting_function_2 <- function(model, newdata){
  subs <-vector(mode='logical', length=nrow(newdata))
  subs[2:length(subs)]<- TRUE

  newX <- model.matrix(model)
  newY <- model$y
  newfit <- coxph(newY ~ newX, iter=0, init=coef(model))
  newfit$var <- model$var

  #print(model)
  #print(newfit)
  #predict(newfit)

  #ret=predict(newfit)

  print("comparison")
  print(paste(" model, original prediction:", paste(predict(model),
collapse=",")))
  print(paste("newfit, original prediction:", paste(predict(newfit),
collapse=",")))

  ret <- predict (newfit, newdata[subs,])
  return(ret)
}

predicting_function_2(fit1, test1)

predicting_function_2(fit2,test1)


-Ursprüngliche Nachricht-
Von: Terry Therneau [mailto:thern...@mayo.edu]
Gesendet: Donnerstag, 14. November 2013 16:31
An: r-help@r-project.org; julian.bo...@elitepartner.de
Betreff: Re: issues with calling predict.coxph.penal (survival) inside a
function

Thanks for the reproducable example.  I can confirm that it fails on my
machine using survival 2-37.5, the next soon-to-be-released version,

The issue is with NextMethod, and my assumption that the called routine
inherited everything from the parent, including the environment chain.  A
simple test this AM showed me that the assumption is false.  It might have
been true for Splus.  Working this out may take some time -- every other
one of my wrestling matches with predict inside a function has -- and
there is a reasonable chance that it won't make this already overdue
release.

In the meantime, here is a workaround that I have sometimes used in other
situations.
Inside your function do the following: fit a new coxph model with fixed
coefficients, and do prediction on that.

myfun <- function(oldfit, subset) {
newX <- model.matrix(oldfit)[subset,]
newY <- oldfit$y[subset]
newfit <- coxph(newY ~ newX, iter=0, init=coef(oldfit))
newfit$var <- oldfit$var
predict(newfit)
}

If the subset is all of a particular strata, as you indicated, then all of
the predictions will be correct.  If not, then those that make use of the
the baseline hazard (type=
expect) will be incorrect but all others are ok.

T

Re: [R] Rotation of parallel lines

2013-11-18 Thread David Winsemius


On Nov 18, 2013, at 7:27 AM, Tonio wrote:




Dear list,

Consider these two parallel segments in a plot.

plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
segments(1, 1, 6, 1)
segments(1, 3, 6, 3)



How can I rotate the two lines together by a defined angle?


Base graphics do not support object operations. You need to do the  
calculation and redraw the plot.


Either lattice or ggplot2 which depend upon the "grid" system would  
have the possibility to "rotate" a component.


--

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
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] Holt Winters for multiple customers and output with R

2013-11-18 Thread Martin, Nick
So I've been working through the HW work here 
http://a-little-book-of-r-for-time-series.readthedocs.org/en/latest/src/timeseries.html
 and have started testing with some "live" customer data. I have a dataset that 
looks like:

CustomerID |   Sales

123456 $5,000

123456 $3,455

123456 $7,540

123456 $2,300

987654 $5,600

987654 $6,700

987654 $1,300

987654 $690

Where I have "Sales" values by customer for the previous 60 months. There are 
~200 customers for which I'm looking to generate a forecast. I'm able to 
generate a forecast for a single customer at a time but am having trouble 
finding guidance on how to run the forecast for the whole group of customers 
and output the results.

Ideally, the output would be the regular forecast output but with Customer ID 
included, like so:

CustomerID | Month | Point.Forecast | Lo.80 |Hi.80 | Lo.95 | Hi.95

Thanks in advance for the help and please let me know if there's any other info 
I can include to help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Simulation study in R for categorical repeated measures data

2013-11-18 Thread Buddhini Gawarammana
Hi everyone,
I am interested in doing a study to compare three analyzing methods namely,
ANOVA, GEE and multilevel approach for *categorical repeated measures data
using a simulation study in R*.
I am not an expert in R but I know some preliminaries in R. Therefore I am
desperately looking for some help to carry on my study.
I would be much obliged if someone could give me some guidance to begin
with my simulations or provide me some sample codes.
 Looking forward for a quick reply.
Thank you.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Ira Fuchs
Thanks for the suggestion. I just tried dput and it did not produce what 
sendmailR requires for the body parameter. Here is a simplified version of what 
I need to do:

> x=matrix(c(1,2,3),1,3)
> x
 [,1] [,2] [,3]
[1,]123
> colnames(x)=c("a","b","c")
> x
 a b c
[1,] 1 2 3

> dput(x)
structure(c(1, 2, 3), .Dim = c(1L, 3L), .Dimnames = list(NULL, 
c("a", "b", "c")))

I want to send x in sendmailR(to,from,x) and have it look more or less like the 
output above. Simple, right?


On Nov 18, 2013, at 9:13 AM, Sarah Goslee wrote:

> What about dput()?
> 
> On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs  wrote:
>> I have a matrix which has colnames and I would like to send this matrix 
>> using sendmailR. How can I convert this simple matrix to a format which can 
>> be used as the body variable in sendmailR? I see how I can create a file 
>> attachment using mime_part but I would like to send the matrix in the body 
>> of the email.
>> 
>> The matrix looks like:
>> 
>>  ABD  DEF  GHI  JKL MNO   TOT
>> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>> 
>> 
>> All the conversions I have tried end up sending the matrix without the 
>> colnames.
>> 
>> Thanks.
>> 

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread Suzen, Mehmet
On 18 November 2013 05:37, Ira Fuchs  wrote:
> I have a matrix which has colnames and I would like to send this matrix using 
> sendmailR. How can I convert this simple matrix

My 1 cent; In case of large objects or full session, suitable for
attachment; RData might be more convenient, i.e., ?save or ?save.image

__
R-help@r-project.org mailing list
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] R for a stats intro for undergrads in the US?

2013-11-18 Thread Liviu Andronic
Dear Spencer,
In case you have similar questions you may want to ask them on
r-sig-teaching, which deals specifically with such topics.

Regards,
Liviu

On Sun, Nov 17, 2013 at 3:19 AM, Spencer Graves
 wrote:
> Hello, All:
>
>
>   Would anyone recommend R for an introductory statistics class for
> freshman psychology students in the US?  If yes, might there be any notes
> for such available?
>
>
>   I just checked r-projects.org and CRAN contributed documentation and
> found nothing.
>
>
>   I have a friend who teaches such a class, and wondered if R might be
> suitable.  The alternative is SPSS at $406 per student.
>
>
>   Thanks,
>   Spencer
>
>
> --
> Spencer Graves, PE, PhD
> President and Chief Technology Officer
> Structure Inspection and Monitoring, Inc.
> 751 Emerson Ct.
> San José, CA 95126
> ph:  408-655-4567
> web:  www.structuremonitoring.com
>
> __
> R-help@r-project.org mailing list
> 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.



-- 
Do you know how to read?
http://www.alienetworks.com/srtest.cfm
http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
Do you know how to write?
http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail

__
R-help@r-project.org mailing list
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] Extract values from vector and repeat by group

2013-11-18 Thread PIKAL Petr
Hi

probably not most elegant and also not general but

rep(df$var[df$time==4],rle(df$group)$lengths)

or

rep(df$var[df$time==4],  sapply(split(df$var,df$group), length))

shall give you desired vector.

Regards
Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Benjamin Gillespie
> Sent: Sunday, November 17, 2013 3:47 PM
> To: r-help@r-project.org
> Subject: [R] Extract values from vector and repeat by group
> 
> Hi all,
> 
> I hope you can help.
> 
> I have a data frame 'df':
> 
> group=c(rep(1,8),rep(2,10),rep(3,11))
> var=rnorm(29)
> time=c(seq(1,8),seq(1,10),seq(1,11))
> df=data.frame(group,var,time)
> 
> I would like to extract the value from 'var' for each 'group' at
> 'time'=4 and repeat these extracted values in a new vector ('new') n
> times where n is the number of rows for each group. I did this by hand
> as below, but there must be a quicker way:
> 
> subset=subset(df,df$time==4)
> subset
> groupvar time
> 4  1  0.25312704
> 12 2 -0.36001284
> 22 3  0.41947304
> 
> df$new=c(rep(0.2531270,8),rep(-0.3600128,10),rep(0.4194730,11))
> 
> Any questions please ask,
> 
> Many thanks in advance,
> 
> Ben Gillespie, Research Postgraduate
> o---o
> School of Geography, University of Leeds, Leeds, LS2 9JT o-
> --o
> Tel: +44(0)113 34 33345
> Mob: +44(0)770 868 7641
> o---o
> http://www.geog.leeds.ac.uk/
> o-o
> @RiversBenG
> o--o
> __
> R-help@r-project.org mailing list
> 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
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] Sending a matrix in an email

2013-11-18 Thread Sarah Goslee
What about dput()?

On Mon, Nov 18, 2013 at 8:35 AM, Ira Fuchs  wrote:
> I have a matrix which has colnames and I would like to send this matrix using 
> sendmailR. How can I convert this simple matrix to a format which can be used 
> as the body variable in sendmailR? I see how I can create a file attachment 
> using mime_part but I would like to send the matrix in the body of the email.
>
> The matrix looks like:
>
>   ABD  DEF  GHI  JKL MNO   TOT
> [1,] 0.44 0.81 1.67 0.37 0.31 -1.18
>
>
> All the conversions I have tried end up sending the matrix without the 
> colnames.
>
> Thanks.
>

__
R-help@r-project.org mailing list
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] Sending a matrix in an email

2013-11-18 Thread ONKELINX, Thierry
Have you tried dput(your.matrix)?

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
Ira Fuchs
Verzonden: maandag 18 november 2013 14:35
Aan: r-help@r-project.org
Onderwerp: [R] Sending a matrix in an email

I have a matrix which has colnames and I would like to send this matrix using 
sendmailR. How can I convert this simple matrix to a format which can be used 
as the body variable in sendmailR? I see how I can create a file attachment 
using mime_part but I would like to send the matrix in the body of the email.

The matrix looks like:

  ABD  DEF  GHI  JKL MNO   TOT
[1,] 0.44 0.81 1.67 0.37 0.31 -1.18


All the conversions I have tried end up sending the matrix without the colnames.

Thanks.

__
R-help@r-project.org mailing list
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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en 
binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is 
door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the 
writer and may not be regarded as stating an official position of INBO, as long 
as the message is not confirmed by a duly signed document.

__
R-help@r-project.org mailing list
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] R Beginner - Need Perhaps 5 - 10 Minutes of R User Time to Learn Few Basics

2013-11-18 Thread PIKAL Petr
Hi

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Zach Feinstein
> Sent: Wednesday, November 13, 2013 2:57 PM
> To: r-help@r-project.org
> Subject: [R] R Beginner - Need Perhaps 5 - 10 Minutes of R User Time to
> Learn Few Basics
> 
> I have finally decided that I will learn R and learn it very well. For

If you really decided to invest in learning R you shall first read R-Intro 
documentation especially chapters 2 and 3 and 1.11.

Eventually you could read whole 102 pages document. It shall not take you more 
than a week and after that you will be able to do quite sophisticated analysis.

I do not know Rstudio or Rattle but once you taste R console way maybe together 
with some suitable editor (I use Tinn-R) you will hardly need any GUI add-on.

Regards
Petr

> now I am using a program that a friend of mine developed to do some
> advanced statistical analyses. I downloaded RStudio to my machine.
> [Perhaps RStudio is not the best platform to work from -  I have heard
> that Rattle is sort of the new standard.] I have so far been able to
> highlight the rows of the code that I wish to run, but then I somehow
> turned off seeing the output. I also cannot find where I would locate
> the output window. Yes, frustrated.
> 
> Would any kind soul be interested in helping kickstart my R learning? I
> have JoinMe installed on my machine so I figure we can do it
> interactively. It should not take more than a few minutes. I am already
> very experienced with both C and VBA languages as well as SPSS syntax
> so there is not much need to worry about me being too much of a novice.
> 
> Thank you very much in advance.
> 
> Zach Feinstein
> zfeinst...@isgmn.com
> (952) 277-0162
> (612) 590-4813 (mobile)
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> 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
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] Sending a matrix in an email

2013-11-18 Thread Ira Fuchs
I have a matrix which has colnames and I would like to send this matrix using 
sendmailR. How can I convert this simple matrix to a format which can be used 
as the body variable in sendmailR? I see how I can create a file attachment 
using mime_part but I would like to send the matrix in the body of the email. 

The matrix looks like:

  ABD  DEF  GHI  JKL MNO   TOT 
[1,] 0.44 0.81 1.67 0.37 0.31 -1.18


All the conversions I have tried end up sending the matrix without the colnames.

Thanks.

__
R-help@r-project.org mailing list
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] Rotation of parallel lines

2013-11-18 Thread Tonio


Dear list, 

Consider these two parallel segments in a plot.

plot(c(1, 6), c(2, 2), type="n", xlim=c(0, 7), ylim=c(-2, 6))
segments(1, 1, 6, 1)
segments(1, 3, 6, 3)



How can I rotate the two lines together by a defined angle?


Thank you all in advance.

Best,
Antonio



Antonio Rivero Ostoic
Assistant professor, PhD

AARHUS UNIVERSITY
School of Business and Social Science
Quantitative Analytics Group and Cognition and Behaviour Lab
Bartholins Allé 10 
DK-8000 Aarhus C

T: +45 871 65421
M: j...@asb.dk

__
R-help@r-project.org mailing list
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] Anova split by factors

2013-11-18 Thread ONKELINX, Thierry
Dear Catalin,

Have a look at the plyr package.

library(plyr)
dlply(
eg,
.(Exp),
function(x) {
aov(masa.uscat.tr~Clona,data=x)
}
)

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data.
~ John Tukey


-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
catalin roibu
Verzonden: maandag 18 november 2013 13:24
Aan: r-help@r-project.org
Onderwerp: [R] Anova split by factors

Hello R-users,
I have a problem with Anova in R and I don't know how to solve that. I want to 
compute Anova for each experiment (exp). I try this code:

test<-lapply(split(eg,eg$Exp),function(x) aov(masa.uscat.tr ~ Clona,data =
x))
or
test<-by(eg,eg$Exp, function(x) aov(masa.uscat.tr~Clona,data=x))

I want to compute Anova summary for each experiment (exp) and I want to compute 
Tuckey test for each Anova.

Thank you very much!

My data is like this:



Exp Plot Clona Prov masa uscat tr masa usc. Ram masa usc total B 36 Max4 P 
Puieti 6.199848485 2.639325843 8.839174328 B 36 Max4 P Puieti 3.87875 1.4798 
5.35855 B 36 Max4 P Puieti 7.822702703 3.32852071 11.15122341 B 36 Max4 P 
Puieti 5.645384615 1.995238095 7.640622711 B 36 Max4 P Puieti 10.2 3.514864865 
13.71486486 B 36 Max4 P Puieti 8.815545455 3.35627907 12.17182452 B 36 Max4 P 
Puieti 5.0 1.607142857 6.64047619 B 36 Max4 P Puieti 6.693488372 
2.630208333 9.323696705 B 36 Max4 P Puieti 6.021012658 1.60293578 7.623948438 B 
36 Max4 P Puieti 10.20582524 3.768314607 13.97413985 B 33 Max4 Butasi 
5.899417476 1.745394737 7.644812213 B 33 Max4 Butasi 3.261428571 1.335735294 
4.597163866 B 33 Max4 Butasi 3.359508197 1.456641221 4.816149418 B 33 Max4 
Butasi 5.036363636 2.097793103 7.13415674 B 33 Max4 Butasi 3.122162162 
1.612012579 4.734174741 B 33 Max4 Butasi 5.042474227 3.246916427 8.289390653 B 
33 Max4 Butasi 5.058255814 2.724299065 7.782554879 B 33 Max4 Butasi 4.977818182 
1!
 .713504274 6.691322455 B 33 Max4 Butasi 3.195294118 1.243411765 4.438705882 B 
33 Max4 Butasi 1.831818182 1.009090909 2.840909091 B 30 AF2 Butasi 6.98195122 
1.764 8.74595122 B 30 AF2 Butasi 5.85833 1.686623377 7.54495671 B 30 AF2 
Butasi 10.625 3.04 13.665 C 39 AF6 Sade 10.27125 2.283193277 12.55444328 C 39 
AF6 Sade 9.473488372 1.909414414 11.38290279 C 39 AF6 Sade 10.4825 2 12.4825 C 
39 AF6 Sade 11.61579545 2.431136364 14.04693182 C 39 AF6 Sade 8.185074627 
1.80933 9.99440796 C 39 AF6 Sade 11.04510638 2.23672956 13.28183594 C 39 
AF6 Sade 9.06667 2.473785714 11.54045238 C 39 AF6 Sade 10.12787611 
3.097631579 13.22550769 C 39 AF6 Sade 9.171290323 1.821226415 10.99251674 C 39 
AF6 Sade 12.1846875 2.262590361 14.44727786 C 42 Pannonia Sade 9.275 
2.482173913 11.75717391 C 42 Pannonia Sade 7.21 1.77 8.98 C 42 Pannonia Sade 
11.36939394 3.111780822 14.48117476 C 42 Pannonia Sade 7.85296875 1.943475177 
9.796443927 C 42 Pannonia Sade 8.25 2.54047619 10.79047619 C 42 Pannonia !
 Sade 8.669277108 2.187071429 10.85634854 C 42 Pannonia Sade 8.51088607
6 2.05344 10.56432608 C 42 Pannonia Sade 9.36222 5.525531915 14.88775414 C 
42 Pannonia Sade 11.08481928 2.573193277 13.65801255 C 42 Pannonia Sade 
10.17462687 3.003225806 13.17785267 C 45 Monviso Sade 12.99693878 3.216083916 
16.21302269 C 45 Monviso Sade 11.11456522 1.885714286 13.0002795 C 45 Monviso 
Sade 8.12933 1.53267 9.662 C 45 Monviso Sade 9.943043478 2.38300885 
12.32605233 C 45 Monviso Sade 11.9805814 3.080923913 15.06150531 C 45 Monviso 
Sade 10.31376623 2.210526316 12.52429255 C 45 Monviso Sade 9.947586207 
1.86083 11.80841954 C 45 Monviso Sade 12.24261538 2.166857143 14.40947253 C 
45 Monviso Sade 13.56650602 2.414371257 15.98087728 C 45 Monviso Sade 
10.87574257 2.922340426 13.798083 C 48 AF2 Sade 9.334545455 2.201822917 
11.53636837 C 48 AF2 Sade 9.747640449 2.811780822 12.55942127 C 48 AF2 Sade 
14.29541284 4.506885246 18.80229809 C 48 AF2 Sade 10.26451613 3.014322581 
13.27883871 C 48 AF2 Sade 13.30924242 3.960661765 17.26990419 C 48 AF2 Sade 
13.232284!
 26 5.00546875 18.23775301 C 48 AF2 Sade 14.8277027 4.450447761 19.27815046 C 
48 AF2 Sade 15.23669528 7.559322034 22.79601731 C 48 AF2 Sade 13.27198582 
3.758252427 17.03023824 C 48 AF2 Sade 13.7136 5.69044 19.40408889 C 51 
Max4 Sade 8.860884956 5.613586957 14.47447191 C 51 Max4 Sade 13.29153285 
5.65306

[R] Anova split by factors

2013-11-18 Thread catalin roibu
Hello R-users,
I have a problem with Anova in R and I don't know how to solve that. I want
to compute Anova for each experiment (exp). I try this code:

test<-lapply(split(eg,eg$Exp),function(x) aov(masa.uscat.tr ~ Clona,data =
x))
or
test<-by(eg,eg$Exp, function(x) aov(masa.uscat.tr~Clona,data=x))

I want to compute Anova summary for each experiment (exp) and I want to
compute Tuckey test for each Anova.

Thank you very much!

My data is like this:



Exp Plot Clona Prov masa uscat tr masa usc. Ram masa usc total
B 36 Max4 P Puieti 6.199848485 2.639325843 8.839174328
B 36 Max4 P Puieti 3.87875 1.4798 5.35855
B 36 Max4 P Puieti 7.822702703 3.32852071 11.15122341
B 36 Max4 P Puieti 5.645384615 1.995238095 7.640622711
B 36 Max4 P Puieti 10.2 3.514864865 13.71486486
B 36 Max4 P Puieti 8.815545455 3.35627907 12.17182452
B 36 Max4 P Puieti 5.0 1.607142857 6.64047619
B 36 Max4 P Puieti 6.693488372 2.630208333 9.323696705
B 36 Max4 P Puieti 6.021012658 1.60293578 7.623948438
B 36 Max4 P Puieti 10.20582524 3.768314607 13.97413985
B 33 Max4 Butasi 5.899417476 1.745394737 7.644812213
B 33 Max4 Butasi 3.261428571 1.335735294 4.597163866
B 33 Max4 Butasi 3.359508197 1.456641221 4.816149418
B 33 Max4 Butasi 5.036363636 2.097793103 7.13415674
B 33 Max4 Butasi 3.122162162 1.612012579 4.734174741
B 33 Max4 Butasi 5.042474227 3.246916427 8.289390653
B 33 Max4 Butasi 5.058255814 2.724299065 7.782554879
B 33 Max4 Butasi 4.977818182 1.713504274 6.691322455
B 33 Max4 Butasi 3.195294118 1.243411765 4.438705882
B 33 Max4 Butasi 1.831818182 1.009090909 2.840909091
B 30 AF2 Butasi 6.98195122 1.764 8.74595122
B 30 AF2 Butasi 5.85833 1.686623377 7.54495671
B 30 AF2 Butasi 10.625 3.04 13.665
C 39 AF6 Sade 10.27125 2.283193277 12.55444328
C 39 AF6 Sade 9.473488372 1.909414414 11.38290279
C 39 AF6 Sade 10.4825 2 12.4825
C 39 AF6 Sade 11.61579545 2.431136364 14.04693182
C 39 AF6 Sade 8.185074627 1.80933 9.99440796
C 39 AF6 Sade 11.04510638 2.23672956 13.28183594
C 39 AF6 Sade 9.06667 2.473785714 11.54045238
C 39 AF6 Sade 10.12787611 3.097631579 13.22550769
C 39 AF6 Sade 9.171290323 1.821226415 10.99251674
C 39 AF6 Sade 12.1846875 2.262590361 14.44727786
C 42 Pannonia Sade 9.275 2.482173913 11.75717391
C 42 Pannonia Sade 7.21 1.77 8.98
C 42 Pannonia Sade 11.36939394 3.111780822 14.48117476
C 42 Pannonia Sade 7.85296875 1.943475177 9.796443927
C 42 Pannonia Sade 8.25 2.54047619 10.79047619
C 42 Pannonia Sade 8.669277108 2.187071429 10.85634854
C 42 Pannonia Sade 8.510886076 2.05344 10.56432608
C 42 Pannonia Sade 9.36222 5.525531915 14.88775414
C 42 Pannonia Sade 11.08481928 2.573193277 13.65801255
C 42 Pannonia Sade 10.17462687 3.003225806 13.17785267
C 45 Monviso Sade 12.99693878 3.216083916 16.21302269
C 45 Monviso Sade 11.11456522 1.885714286 13.0002795
C 45 Monviso Sade 8.12933 1.53267 9.662
C 45 Monviso Sade 9.943043478 2.38300885 12.32605233
C 45 Monviso Sade 11.9805814 3.080923913 15.06150531
C 45 Monviso Sade 10.31376623 2.210526316 12.52429255
C 45 Monviso Sade 9.947586207 1.86083 11.80841954
C 45 Monviso Sade 12.24261538 2.166857143 14.40947253
C 45 Monviso Sade 13.56650602 2.414371257 15.98087728
C 45 Monviso Sade 10.87574257 2.922340426 13.798083
C 48 AF2 Sade 9.334545455 2.201822917 11.53636837
C 48 AF2 Sade 9.747640449 2.811780822 12.55942127
C 48 AF2 Sade 14.29541284 4.506885246 18.80229809
C 48 AF2 Sade 10.26451613 3.014322581 13.27883871
C 48 AF2 Sade 13.30924242 3.960661765 17.26990419
C 48 AF2 Sade 13.23228426 5.00546875 18.23775301
C 48 AF2 Sade 14.8277027 4.450447761 19.27815046
C 48 AF2 Sade 15.23669528 7.559322034 22.79601731
C 48 AF2 Sade 13.27198582 3.758252427 17.03023824
C 48 AF2 Sade 13.7136 5.69044 19.40408889
C 51 Max4 Sade 8.860884956 5.613586957 14.47447191
C 51 Max4 Sade 13.29153285 5.653061224 18.94459407
C 51 Max4 Sade 9.609850746 3.385714286 12.99556503

-- 
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
   +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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] Extract values from vector and repeat by group

2013-11-18 Thread Benjamin Gillespie
Brilliant - thanks for all the really useful suggestions, problem = solved.

Many thanks,

Ben Gillespie, Research Postgraduate
o---o
School of Geography, University of Leeds, Leeds, LS2 9JT
o---o
Tel: +44(0)113 34 33345
Mob: +44(0)770 868 7641
o---o
http://www.geog.leeds.ac.uk/
o-o
@RiversBenG
o--o

From: arun [smartpink...@yahoo.com]
Sent: 17 November 2013 16:48
To: R help
Cc: Berend Hasselman; Benjamin Gillespie
Subject: Re: [R] Extract values from vector and repeat by group

Hi,

?merge() sometimes change the order.
For example:
df1 <- df[-12,]
df2 <- df1

merge(df1, df1[df1$time == 4, c("group", "var")], by.x = "group", by.y = 
"group", suffixes = c("", "GroupSK0"))

In that case,

df1$ord1 <- with(df1,order(group,time))
res <- merge(df1, df1[df1$time == 4, c("group", "var")], by.x = "group", by.y = 
"group", suffixes = c("", "GroupSK0"))
res[order(res$ord1),-4]


#or just
library(plyr)
join(df2,df2[df2$time==4,c("group","var")],by="group",type="inner")


#or you may use:

indx <- with(df1,ave(time==4,group,FUN=any))

 ddply(df1[indx,],.(group),mutate,new=var[time==4])

A.K.






On Sunday, November 17, 2013 10:22 AM, Berend Hasselman  wrote:

On 17-11-2013, at 15:47, Benjamin Gillespie  wrote:

> Hi all,
>
> I hope you can help.
>
> I have a data frame 'df':
>
> group=c(rep(1,8),rep(2,10),rep(3,11))
> var=rnorm(29)
> time=c(seq(1,8),seq(1,10),seq(1,11))
> df=data.frame(group,var,time)
>
> I would like to extract the value from 'var' for each 'group' at 'time'=4 and 
> repeat these extracted values in a new vector ('new') n times where n is the 
> number of rows for each group. I did this by hand as below, but there must be 
> a quicker way:
>
> subset=subset(df,df$time==4)
> subset
> groupvar time
> 4  1  0.25312704
> 12 2 -0.36001284
> 22 3  0.41947304
>
> df$new=c(rep(0.2531270,8),rep(-0.3600128,10),rep(0.4194730,11))
>
> Any questions please ask,

A very similar question was recently asked on Stackoverflow: 
http://stackoverflow.com/questions/19971763/r-programming-normalizing-a-column-of-data-by-another-entry-in-2-other-columns

>From the answer given there you could try this

set.seed(11) # to make it reproducible

group=c(rep(1,8),rep(2,10),rep(3,11))
var=rnorm(29)
time=c(seq(1,8),seq(1,10),seq(1,11))
df=data.frame(group,var,time)

#df
#df[df$time==4, c("group", "var")]

# merge into original data.frame
df <- merge(df, df[df$time == 4, c("group", "var")], by.x = "group", by.y = 
"group", suffixes = c("", "GroupSK0"))
df

Berend


__
R-help@r-project.org mailing list
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
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] Hide return values

2013-11-18 Thread Chris89
Awesome, thanks!

-Chris



--
View this message in context: 
http://r.789695.n4.nabble.com/Hide-return-values-tp4680611p4680666.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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.