Re: [R] question about the axis label

2011-01-25 Thread Uwe Ligges

Unfortunately, this fine control is only hardly possible:

1. [x,y].ticklabs labels the ticks that are in the plot. If there are 
less ticks than ticklabs, the ticklabs are recycled and hence overlap.


2. xlim should do the trick to restrict to a certain range of values. It 
does not precisely and this is a known unfixed (and hard to fix by 
design) bug.


3. What you can do is enhance the number of ticks by telling R how many 
ticks to use approximately as in:


  scatterplot3d(dat, type = h,
lab = c(12, 10,0), lab.z = 8, scale.y = 0.7)

where dat is your data.frame.
This tells R to
 - use approx. 12 ticks on x-axis
 - use approx. 10 ticks on y-axis
 - use approx. 8 ticks on z axis
 - scale y length by factor of 0.7

Best wishes,
uwe






On 25.01.2011 08:53, 孟欣 wrote:

Hello sir:
I have a question about the axis label of scatterplot3d function.
The data is in the attachment.
If I use the command:
scatterplot3d(x,y,z,type=h)
I want the plot's x-axis lab to be 1,2,3,...,13, y-axis lab to be
1,2,3,...11
But if I use the command:
scatterplot3d(x,y,z,type=h,x.ticklabs=1:13,y.ticklabs=1:11)
The axis labs are overlap, still can't get what I want.
I'm in difficulty in how to set the axis labels,which need your
suggestion very much.
Thanks for your help.
My best.




__
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] Extract NA data rows

2011-01-25 Thread typhoong

hi i have the following dataframe 

x   y
1   345
6   NA
8   123
32  123
12  NA
6   124
7   NA

and i want to extract the data rows which contains NA data, I tried

subset(dataframe,y==NA) 

but fail. if you know the answers, please let me know thanks.

typhoong






-- 
View this message in context: 
http://r.789695.n4.nabble.com/Extract-NA-data-rows-tp3235568p3235568.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] setting headers in POST

2011-01-25 Thread fayazvf

I need to use an API which requires me set certain attribute=values pairs in
the header.
The postToHost() method allows only to send data in the body.
Please help me.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/setting-headers-in-POST-tp3235542p3235542.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] Using open calais in R

2011-01-25 Thread fayazvf

I am using calais api in R for text analysis.
But im facing a some problem when fetching the rdf from the server.
I'm using the getToHost() method for the api call but i get just a null
string.
The same url in browser returns an RDF document. 

getToHost(www.api.opencalais.com,/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=)
[1] 
http://api.opencalais.com/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=;
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Using-open-calais-in-R-tp3235597p3235597.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] question about the axis label

2011-01-25 Thread 孟欣
Hello sir:
I have a question about the axis label of scatterplot3d function.
The data is in the attachment.
 
If I use the command:
scatterplot3d(x,y,z,type=h)
 
I want the  plot's x-axis lab to be 1,2,3,...,13, y-axis lab to be 1,2,3,...11
 
But if I use the command:
scatterplot3d(x,y,z,type=h,x.ticklabs=1:13,y.ticklabs=1:11)
The axis labs are overlap, still can't get what I want.
 
I'm in difficulty in how to set the axis labels,which need your suggestion very 
much.
 
Thanks for your help.
 
My best.
 
 way nation  fre
1   1   0
1   2   1
1   3   1317
1   4   0
1   5   0
1   6   0
1   7   1
1   8   1
1   9   1
1   10  16
1   11  2
2   1   0
2   2   0
2   3   35
2   4   0
2   5   0
2   6   0
2   7   0
2   8   0
2   9   3
2   10  0
2   11  0
3   1   12
3   2   8
3   3   539
3   4   38
3   5   7
3   6   0
3   7   6
3   8   7
3   9   325
3   10  36
3   11  15
4   1   0
4   2   0
4   3   2
4   4   0
4   5   0
4   6   0
4   7   0
4   8   0
4   9   1
4   10  0
4   11  0
5   1   0
5   2   0
5   3   4
5   4   1
5   5   0
5   6   0
5   7   0
5   8   0
5   9   4
5   10  0
5   11  2
6   1   0
6   2   0
6   3   0
6   4   0
6   5   0
6   6   0
6   7   0
6   8   0
6   9   1
6   10  0
6   11  0
7   1   0
7   2   0
7   3   1
7   4   0
7   5   0
7   6   0
7   7   0
7   8   0
7   9   0
7   10  0
7   11  0
8   1   0
8   2   0
8   3   128
8   4   2
8   5   0
8   6   0
8   7   0
8   8   0
8   9   0
8   10  0
8   11  1
9   1   0
9   2   0
9   3   22
9   4   0
9   5   0
9   6   0
9   7   0
9   8   0
9   9   3
9   10  0
9   11  0
10  1   0
10  2   0
10  3   8
10  4   0
10  5   0
10  6   0
10  7   0
10  8   0
10  9   2
10  10  0
10  11  0
11  1   0
11  2   0
11  3   6
11  4   0
11  5   0
11  6   0
11  7   0
11  8   1
11  9   0
11  10  0
11  11  0
12  1   0
12  2   0
12  3   124
12  4   1
12  5   0
12  6   10
12  7   0
12  8   0
12  9   5
12  10  1
12  11  0
13  1   5
13  2   3
13  3   561
13  4   7
13  5   3
13  6   0
13  7   7
13  8   9
13  9   50
13  10  7
13  11  45
__
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] crazy loop error.

2011-01-25 Thread Petr Savicky
On Mon, Jan 24, 2011 at 11:18:35PM +0100, Roy Mathew wrote:
 Thanks for the reply Erik, As you mentioned, grouping consecutive elements
 of 'a' was my idea.
 I am unaware of any R'ish way to do it. It would be nice if someone in the
 community knows this.
 
 The error resulting in the NA was pretty easy to fix, and my loop works, but
 the results are still wrong (new script below).
 Ideally it should print single hello for the single letters and grouped '3
 hellos' for the fives, grouped '2 hellos' for the sixes etc.
 
 Based on the run results, if the value of n is being tracked, it changes
 quite unpredictably.
 Can someone explain how the value of n changes from end of the loop to the
 top without anything being done to it?

Hi.

A for-loop in R is different from a for-loop in C. It is similar
to foreach loop in Perl. If v is a vector, then

  for (n in v)

first creates the vector v and then always performs length(v) iterations.
Before iteration i, n is assigned v[i] even if n is changed in the
previous iteration.

If you want to control the loop variable during execution, it is possible
to use a while loop, where you have full control. While loop may be better
also if v has a very large length, since, for example

  for (n in 1:100)

creates a vector of length 100 in memory.

It should also be noted that the for-loop

  for (n in 1:k)

performs 2 iterations, if k is 0, since 1:0 is a vector of length 2.
If k may be 0, then it is better to use

  for (n in seq(length=k))

since seq(length=0) has length 0.

Hope this helps.

Petr Savicky.

__
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] crazy loop error.

2011-01-25 Thread Petr PIKAL
Hi


r-help-boun...@r-project.org napsal dne 24.01.2011 23:18:35:

 Thanks for the reply Erik, As you mentioned, grouping consecutive 
elements
 of 'a' was my idea.
 I am unaware of any R'ish way to do it. It would be nice if someone in 
the
 community knows this.
 
 The error resulting in the NA was pretty easy to fix, and my loop works, 
but
 the results are still wrong (new script below).
 Ideally it should print single hello for the single letters and 
grouped '3
 hellos' for the fives, grouped '2 hellos' for the sixes etc.
 
 Based on the run results, if the value of n is being tracked, it changes
 quite unpredictably.
 Can someone explain how the value of n changes from end of the loop to 
the
 top without anything being done to it?

Put it into a foo function and make use debug(fun())

Regards
Petr

BTW mapply solution is shorter and probably quicker and easier to 
maintain.

 I cannot figure out what I am doing wrong.
 
 a-c(2,3,5,5,5,6,6,7)
 
 for(n in 1:length(a))
 {
 print(paste(n: ,n))
 z1-a[n]
 print(paste(z1:,z1))
 #make a list container
 ldata-list()
 t=1
 
 while(z1==a[n])
 {
 
 #add dataframes to list
 ldata[[t]]-paste(hello)
 
 n=n+1
 t=t+1
 
 if(nlength(a))
 {
 break;
 }
 }
 print(--End of while loop---)
 
 for(y in 1:length(ldata))
 {
 print(ldata[[y]])
 }
 
 print(paste(n: ,n))
 print(**End of for loop)
 }
 
 
 Thanks,
 Roy
 
[[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] Extract NA data rows

2011-01-25 Thread David Scott

On 25/01/2011 8:07 p.m., typhoong wrote:


hi i have the following dataframe

x   y
1   345
6   NA
8   123
32  123
12  NA
6   124
7   NA

and i want to extract the data rows which contains NA data, I tried

subset(dataframe,y==NA)

but fail. if you know the answers, please let me know thanks.

typhoong



Your test is wrong for NA. You must use is.na:

 df
   x   y
1  1 345
2  6  NA
3  8 123
4 32 123
5 12  NA
6  6 124
7  7  NA
 subset(df, is.na(y))
   x  y
2  6 NA
5 12 NA
7  7 NA


--
_
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142,NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:  d.sc...@auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

__
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] Odp: Extract NA data rows

2011-01-25 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 25.01.2011 08:07:10:

 
 hi i have the following dataframe 
 
 x   y
 1   345
 6   NA
 8   123
 32   123
 12   NA
 6   124
 7   NA
 
 and i want to extract the data rows which contains NA data, I tried
 
 subset(dataframe,y==NA) 

See

?is.na

however ?complete.cases is my preferred choice when working with data 
frames and several columns.

dataframe[complete.cases(dataframe),]

Regards
Petr

 
 but fail. if you know the answers, please let me know thanks.
 
 typhoong
 
 
 
 
 
 
 -- 
 View this message in context: 
http://r.789695.n4.nabble.com/Extract-NA-data-
 rows-tp3235568p3235568.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.


Re: [R] Extract NA data rows

2011-01-25 Thread Ivan Calandra

Hi!

Try
subset(dataframe, is.na(y))

or
df[is.na(df$y),]

HTH,
Ivan

Le 1/25/2011 08:07, typhoong a écrit :

hi i have the following dataframe

x   y
1   345
6   NA
8   123
32  123
12  NA
6   124
7   NA

and i want to extract the data rows which contains NA data, I tried

subset(dataframe,y==NA)

but fail. if you know the answers, please let me know thanks.

typhoong








--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] Problems plotting the efficient frontier with fPortfolio

2011-01-25 Thread Luis Felipe Parra
Hello, I have some simulations of financial data, I have 17 variables
simulated 1000 times to three horizons. I am tring to plot the efficient
frontier which I already obtained  using th fPortfolio package. I am using
the following commands:

Data=timeSeries(X[1,,])
lppSpec - portfolioSpec()
longFrontier - portfolioFrontier(Data, lppSpec)
plot(longFrontier)
Selección: 1
Error en dimnames(x) - dn :
  la longitud de 'dimnames' [1] no es igual a la extensión del arreglo
 tailoredFrontierPlot(object = longFrontier, mText = MV Portfolio -
LongOnlyConstraints,risk = Cov)
Error en dimnames(x) - dn :
  la longitud de 'dimnames' [1] no es igual a la extensión del arreglo

and getting the error that appears. I also tried to do the same with the
same data changing the solver to solveRshortExact and using the Short
constraints and got the same error. Does anybody know what might be going
on? 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] crazy loop error.

2011-01-25 Thread Prof Brian Ripley

On Tue, 25 Jan 2011, Petr Savicky wrote:


On Mon, Jan 24, 2011 at 11:18:35PM +0100, Roy Mathew wrote:

Thanks for the reply Erik, As you mentioned, grouping consecutive elements
of 'a' was my idea.
I am unaware of any R'ish way to do it. It would be nice if someone in the
community knows this.

The error resulting in the NA was pretty easy to fix, and my loop works, but
the results are still wrong (new script below).
Ideally it should print single hello for the single letters and grouped '3
hellos' for the fives, grouped '2 hellos' for the sixes etc.

Based on the run results, if the value of n is being tracked, it changes
quite unpredictably.
Can someone explain how the value of n changes from end of the loop to the
top without anything being done to it?


Hi.

A for-loop in R is different from a for-loop in C. It is similar
to foreach loop in Perl. If v is a vector, then

 for (n in v)

first creates the vector v and then always performs length(v) iterations.
Before iteration i, n is assigned v[i] even if n is changed in the
previous iteration.


And also if v is changed during the loop.


If you want to control the loop variable during execution, it is possible
to use a while loop, where you have full control. While loop may be better
also if v has a very large length, since, for example

 for (n in 1:100)

creates a vector of length 100 in memory.

It should also be noted that the for-loop

 for (n in 1:k)

performs 2 iterations, if k is 0, since 1:0 is a vector of length 2.
If k may be 0, then it is better to use

 for (n in seq(length=k))

since seq(length=0) has length 0.


Since you keep mentioning that, it is actually much better to use 
seq_len(k) (and seq_along(x) instead of your earlier recommendation of 
seq(along=x)).  And if you are using seq() in other cases in programs, 
consider seq.int() instead.



Hope this helps.

Petr Savicky.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] Subtracting elements of data.frame

2011-01-25 Thread Vincy Pyne
Dear R helpers

I have a dataframe as

df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))

 df
   x   y
1  1 102
2 14 500
3  3  40
4 21 101
5 11 189

# Actually I am having dataframe having multiple columns. I am just giving an 
example.

I need to subtract all the rows of df by the first row of df i.e. I need to 
subtract each element of 'x' column by 1. Likewise I need to subtract all 
elements of column 'y' by 11. Thus I need an output like

 df_new
   x   y
1  0   0
2 13 398
3  2 -62
4 20  -1
5 10  87

As I had mentioned above, I have number of columns in reality and thus I can't 
use the command
 say

df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

Kindly guide

Thanking you all in advance

Regards

Vincy



[[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] ggplot geom_boxplot and stat_smooth

2011-01-25 Thread Dennis Murphy
Hi Petr:

I had to do a little bit of finagling, but this seems to work. I basically
did the following:

(i) coordinated the dodging of the points and boxplots by typ within konc.f;
(ii) summarized the group medians in a separate data frame and added an
additional
column to compensate for the offsets in the boxplots due to dodging
(iii) used geom_line() with group typ to get the connecting lines.

# library(ggplot2)

# Summarize group medians
ads - ddply(ad, .(konc.f, typ), summarise, m = median(bel))
# Offset x-positions
ads$pos - rep(c(1:4, 6, 7), each = 4) + rep(c(-0.3, -0.1, 0.1, 0.3), 6)

# Note use of position_dodge() with same width in both the boxplot and point
geoms
# Add geom_line with summarized data frame and offset x-positions
# group = typ produces a separate line per typ

p + geom_boxplot(position = position_dodge(width = 0.8)) +
geom_point(position = position_dodge(width = 0.8)) +
geom_line(data = ads, aes(x = pos, y = m, colour = typ, group = typ))

I chose to create a separate data frame for the summaries rather than use
stat_summary(), for example, because it is a bit easier to plot individual
layers that way.

HTH,
Dennis

On Mon, Jan 24, 2011 at 11:05 PM, Petr PIKAL petr.pi...@precheza.cz wrote:

 Dear all

 I would like to superpose some smoothing line through boxplot in ggplot

  dput(ad)
 structure(list(konc.f = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L,
 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L,
 7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L,
 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L,
 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 7L, 7L, 7L), .Label =
 c((189,196],
 (196,202], (202,208], (208,215], (215,221], (221,227],
 (227,234]), class = factor), bel = c(99.28, 99.29, 99.25,
 98.13, 99.51, 99.21, 99.09, 97.84, 98.97, 98.48, 98.64, 98.09,
 98.44, 98.19, 98.25, 97.54, 99.11, 98.23, 97.62, 97.01, 97.62,
 97.58, 97.42, 97.75, 97.16, 96.79, 96.82, 98.8, 99.02, 98.86,
 98.85, 99.25, 98.46, 98.68, 98.3, 98.67, 98.54, 98.39, 98.18,
 98.54, 99.13, 98.92, 98.29, 98.78, 98.58, 98.78, 98.9, 98.18,
 97.5, 98.63, 97.53, 96.55, 96.52, 96.23, 95.54, 95.54, 96.33,
 95.91, 95.41, 94.98, 94.69, 93.95, 94.05, 95.22, 94.6, 94.27,
 93.44, 95.15, 94.62, 93.86, 94.51, 94.83, 93.66, 92.95, 94.4,
 93.17, 92.77, 95.79, 95.03, 94.96, 95.94, 95.71, 95.19, 95.11,
 94.91, 94.42, 94.68, 94.91, 94.66, 94.05, 93.57, 93.43, 94.77,
 93.58, 93.84, 93.24, 94.45, 93.57, 93.46, 92.38, 92.39, 94.07
 ), typ = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(alrut,
 nealrut, stan, vlakan), class = factor)), .Names = c(konc.f,
 bel, typ), row.names = c(NA, -102L), class = data.frame)
 

 Here is what I did

 p-ggplot(ad, aes(x=konc.f, y=bel, colour=typ))
 p+geom_boxplot()+geom_jitter(position=position_jitter(w=0.1))+stat_smooth()
 geom_smooth: Only one unique x value each group.Maybe you want aes(group =
 1)?

 I get nice picture with boxes but I expected to get something like
 smoothing line through box centres.

 Is it possible without some hack to stat_smooth code?

 Regards
 Petr

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


[[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 NA data rows

2011-01-25 Thread kamel gaanoun
Hi,

May be try this :

data[which(is.na(data[,2])),]

2011/1/25 typhoong graham...@eurus-energy.com


 hi i have the following dataframe

 x   y
 1   345
 6   NA
 8   123
 32  123
 12  NA
 6   124
 7   NA

 and i want to extract the data rows which contains NA data, I tried

 subset(dataframe,y==NA)

 but fail. if you know the answers, please let me know thanks.

 typhoong






 --
 View this message in context:
 http://r.789695.n4.nabble.com/Extract-NA-data-rows-tp3235568p3235568.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.




-- 
Kamel Gaanoun
(+33) (0)6.76.04.65.77

[[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] crazy loop error.

2011-01-25 Thread Petr Savicky
On Tue, Jan 25, 2011 at 09:05:03AM +0100, Petr Savicky wrote:
[...]
 to foreach loop in Perl. If v is a vector, then
 
   for (n in v)
 
 first creates the vector v and then always performs length(v) iterations.

I forgot that ‘break’ may stop the loop. See ?for for further
information. In particular, it says

  You can assign to ‘var’ within the body of the loop, but
  this will not affect the next iteration.

Petr Savicky.

__
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] crazy loop error.

2011-01-25 Thread Roy Mathew
Dear Erik,
Thanks for the mapply idea. I never got around to understand all those apply
functions.
I am still curious as to why the other loop didnt work. I even tried the
debug but doesnt help.
Anyway I will leave that for now.
Thanks a lot for your help.
Regards,
Roy


On Mon, Jan 24, 2011 at 11:43 PM, Erik Iverson er...@ccbr.umn.edu wrote:



 Roy Mathew wrote:

 Thanks for the reply Erik, As you mentioned, grouping consecutive elements
 of 'a' was my idea. I am unaware of any R'ish way to do it. It would be nice
 if someone in the community knows this.


 Is this the idea you're trying to execute?  It uses ?rle and ?mapply.


 a - c(2,3,5,5,5,6,6,7)
 mapply(rep, hello, rle(a)$lengths, USE.NAMES = FALSE)

 [[1]]
 [1] hello

 [[2]]
 [1] hello

 [[3]]
 [1] hello hello hello

 [[4]]
 [1] hello hello

 [[5]]
 [1] hello




-- 
Best Regards,
Roy

[[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] Subtracting elements of data.frame

2011-01-25 Thread Dennis Murphy
Hi:

 df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
 apply(df, 2, function(x) x - x[1])
  x   y
[1,]  0   0
[2,] 13 398
[3,]  2 -62
[4,] 20  -1
[5,] 10  87

HTH,
Dennis

On Tue, Jan 25, 2011 at 1:20 AM, Vincy Pyne vincy_p...@yahoo.ca wrote:

 Dear R helpers

 I have a dataframe as

 df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))

  df
x   y
 1  1 102
 2 14 500
 3  3  40
 4 21 101
 5 11 189

 # Actually I am having dataframe having multiple columns. I am just giving
 an example.

 I need to subtract all the rows of df by the first row of df i.e. I need to
 subtract each element of 'x' column by 1. Likewise I need to subtract all
 elements of column 'y' by 11. Thus I need an output like

  df_new
x   y
 1  0   0
 2 13 398
 3  2 -62
 4 20  -1
 5 10  87

 As I had mentioned above, I have number of columns in reality and thus I
 can't use the command
  say

 df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

 Kindly guide

 Thanking you all in advance

 Regards

 Vincy



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



[[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] Subtracting elements of data.frame

2011-01-25 Thread Ivan Calandra

Hi,

Try this:
df_new - as.data.frame(lapply(df, FUN=function(x) x-x[1]))

I hope it works!
Ivan

Le 1/25/2011 10:20, Vincy Pyne a écrit :

Dear R helpers

I have a dataframe as

df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))


df

x   y
1  1 102
2 14 500
3  3  40
4 21 101
5 11 189

# Actually I am having dataframe having multiple columns. I am just giving an 
example.

I need to subtract all the rows of df by the first row of df i.e. I need to 
subtract each element of 'x' column by 1. Likewise I need to subtract all 
elements of column 'y' by 11. Thus I need an output like


df_new

x   y
1  0   0
2 13 398
3  2 -62
4 20  -1
5 10  87

As I had mentioned above, I have number of columns in reality and thus I can't 
use the command
  say

df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

Kindly guide

Thanking you all in advance

Regards

Vincy



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


--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] Subtracting elements of data.frame

2011-01-25 Thread Ivan Calandra

I always forget about sapply():
df_new - sapply(df, FUN=function(x) x-x[1])

Ivan

Le 1/25/2011 10:33, Ivan Calandra a écrit :

Hi,

Try this:
df_new - as.data.frame(lapply(df, FUN=function(x) x-x[1]))

I hope it works!
Ivan

Le 1/25/2011 10:20, Vincy Pyne a écrit :

Dear R helpers

I have a dataframe as

df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))


df

x   y
1  1 102
2 14 500
3  3  40
4 21 101
5 11 189

# Actually I am having dataframe having multiple columns. I am just 
giving an example.


I need to subtract all the rows of df by the first row of df i.e. I 
need to subtract each element of 'x' column by 1. Likewise I need to 
subtract all elements of column 'y' by 11. Thus I need an output like



df_new

x   y
1  0   0
2 13 398
3  2 -62
4 20  -1
5 10  87

As I had mentioned above, I have number of columns in reality and 
thus I can't use the command

  say

df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

Kindly guide

Thanking you all in advance

Regards

Vincy



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




--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] review of R Graphs Cookbook

2011-01-25 Thread Patrick Burns

If you are foolish enough not to be
following R Bloggers via RSS or twitter,
you might miss:

http://www.portfolioprobe.com/2011/01/24/review-of-r-graphs-cookbook-by-hrishi-mittal/

Executive summary:
Extremely useful for new users, informative
to even quite seasoned users.

--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

__
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] crazy loop error.

2011-01-25 Thread Ivan Calandra

Mr Ripley,

May I ask why seq_len() and seq_along() are better than seq()?

Thanks,
Ivan

Le 1/25/2011 09:58, Prof Brian Ripley a écrit :

On Tue, 25 Jan 2011, Petr Savicky wrote:


On Mon, Jan 24, 2011 at 11:18:35PM +0100, Roy Mathew wrote:
Thanks for the reply Erik, As you mentioned, grouping consecutive 
elements

of 'a' was my idea.
I am unaware of any R'ish way to do it. It would be nice if someone 
in the

community knows this.

The error resulting in the NA was pretty easy to fix, and my loop 
works, but

the results are still wrong (new script below).
Ideally it should print single hello for the single letters and 
grouped '3

hellos' for the fives, grouped '2 hellos' for the sixes etc.

Based on the run results, if the value of n is being tracked, it 
changes

quite unpredictably.
Can someone explain how the value of n changes from end of the loop 
to the

top without anything being done to it?


Hi.

A for-loop in R is different from a for-loop in C. It is similar
to foreach loop in Perl. If v is a vector, then

 for (n in v)

first creates the vector v and then always performs length(v) 
iterations.

Before iteration i, n is assigned v[i] even if n is changed in the
previous iteration.


And also if v is changed during the loop.

If you want to control the loop variable during execution, it is 
possible
to use a while loop, where you have full control. While loop may be 
better

also if v has a very large length, since, for example

 for (n in 1:100)

creates a vector of length 100 in memory.

It should also be noted that the for-loop

 for (n in 1:k)

performs 2 iterations, if k is 0, since 1:0 is a vector of length 2.
If k may be 0, then it is better to use

 for (n in seq(length=k))

since seq(length=0) has length 0.


Since you keep mentioning that, it is actually much better to use 
seq_len(k) (and seq_along(x) instead of your earlier recommendation of 
seq(along=x)).  And if you are using seq() in other cases in programs, 
consider seq.int() instead.



Hope this helps.

Petr Savicky.




--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] ggplot geom_boxplot and stat_smooth

2011-01-25 Thread Petr PIKAL
Thank you

I did not realise I can simply add data from different source data frame 
to constructed graph. It even works with stat_smooth() quite 
straightforward. One is always learning new tricks.

Best regards
Petr

r-help-boun...@r-project.org napsal dne 25.01.2011 10:24:42:

 Hi Petr:
 
 I had to do a little bit of finagling, but this seems to work. I 
basically
 did the following:
 
 (i) coordinated the dodging of the points and boxplots by typ within 
konc.f;
 (ii) summarized the group medians in a separate data frame and added an
 additional
 column to compensate for the offsets in the boxplots due to dodging
 (iii) used geom_line() with group typ to get the connecting lines.
 
 # library(ggplot2)
 
 # Summarize group medians
 ads - ddply(ad, .(konc.f, typ), summarise, m = median(bel))
 # Offset x-positions
 ads$pos - rep(c(1:4, 6, 7), each = 4) + rep(c(-0.3, -0.1, 0.1, 0.3), 6)
 
 # Note use of position_dodge() with same width in both the boxplot and 
point
 geoms
 # Add geom_line with summarized data frame and offset x-positions
 # group = typ produces a separate line per typ
 
 p + geom_boxplot(position = position_dodge(width = 0.8)) +
 geom_point(position = position_dodge(width = 0.8)) +
 geom_line(data = ads, aes(x = pos, y = m, colour = typ, group = 
typ))
 
 I chose to create a separate data frame for the summaries rather than 
use
 stat_summary(), for example, because it is a bit easier to plot 
individual
 layers that way.
 
 HTH,
 Dennis
 
 On Mon, Jan 24, 2011 at 11:05 PM, Petr PIKAL petr.pi...@precheza.cz 
wrote:
 
  Dear all
 
  I would like to superpose some smoothing line through boxplot in 
ggplot
 
   dput(ad)
  structure(list(konc.f = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L,
  2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L,
  7L, 7L, 7L, 7L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L,
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L,
  1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L,
  6L, 6L, 6L, 7L, 7L, 7L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
  3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 6L, 6L, 6L, 6L, 7L, 7L, 7L), .Label =
  c((189,196],
  (196,202], (202,208], (208,215], (215,221], (221,227],
  (227,234]), class = factor), bel = c(99.28, 99.29, 99.25,
  98.13, 99.51, 99.21, 99.09, 97.84, 98.97, 98.48, 98.64, 98.09,
  98.44, 98.19, 98.25, 97.54, 99.11, 98.23, 97.62, 97.01, 97.62,
  97.58, 97.42, 97.75, 97.16, 96.79, 96.82, 98.8, 99.02, 98.86,
  98.85, 99.25, 98.46, 98.68, 98.3, 98.67, 98.54, 98.39, 98.18,
  98.54, 99.13, 98.92, 98.29, 98.78, 98.58, 98.78, 98.9, 98.18,
  97.5, 98.63, 97.53, 96.55, 96.52, 96.23, 95.54, 95.54, 96.33,
  95.91, 95.41, 94.98, 94.69, 93.95, 94.05, 95.22, 94.6, 94.27,
  93.44, 95.15, 94.62, 93.86, 94.51, 94.83, 93.66, 92.95, 94.4,
  93.17, 92.77, 95.79, 95.03, 94.96, 95.94, 95.71, 95.19, 95.11,
  94.91, 94.42, 94.68, 94.91, 94.66, 94.05, 93.57, 93.43, 94.77,
  93.58, 93.84, 93.24, 94.45, 93.57, 93.46, 92.38, 92.39, 94.07
  ), typ = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
  3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
  3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
  4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L,
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
  1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c(alrut,
  nealrut, stan, vlakan), class = factor)), .Names = c(konc.f,
  bel, typ), row.names = c(NA, -102L), class = data.frame)
  
 
  Here is what I did
 
  p-ggplot(ad, aes(x=konc.f, y=bel, colour=typ))
  
p+geom_boxplot()+geom_jitter(position=position_jitter(w=0.1))+stat_smooth()
  geom_smooth: Only one unique x value each group.Maybe you want 
aes(group =
  1)?
 
  I get nice picture with boxes but I expected to get something like
  smoothing line through box centres.
 
  Is it possible without some hack to stat_smooth code?
 
  Regards
  Petr
 
  __
  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.
 
 
[[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] Masking commands - Permutation in gregmisc and e1071

2011-01-25 Thread Uwe Ligges



On 24.01.2011 23:53, Peter Langfelder wrote:

On Mon, Jan 24, 2011 at 2:47 PM, Yanika Borgakina...@gmail.com  wrote:

I am using the function permutations from the package *gregmisc*. However, I
am also making use of the package *e1071*, which also contains a function
called permutations. I want to use the function permutations from the *
gregmisc* package, however, the other package is masking this function. This
happens both when I load the *e1071* package before *gregmisc* and when I
load *e1071* after I load *gregmisc*.

Is there any specific command to use the permutation from one package and
not the other please?


To specify package when you call a function, use
package::function(...), for example
gregmisc::permutations.



You may also want to read about the NAMESPACE mechanism in R.

Best,
Uwe Ligges



Peter

__
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] how to get loglik parameter from splm package?

2011-01-25 Thread Millo Giovanni
Dear useR,

although I admit that getting the log likelihood is important, you must
concede that obtaining the parameter estimates is not bad either.
Regarding craze, well there are crazier things in the world than this,
just look at the political situation in Italy.

Anyway, the loglik has always been there, although it wasn't exported
(hence the NULL value). In the most recent versions of 'splm' we have
made it available, at least for RE models, through the standard way: a
logLik() method. Usage:

 logLik(yourmodel)

You can download it from R-forge, as usual.

Best,
Giovanni

 original message --

Message: 42
Date: Mon, 24 Jan 2011 06:59:39 -0800 (PST)
From: zhaowei zao_...@msn.com
To: r-help@r-project.org
Subject: [R] how to get loglik parameter from splm package?
Message-ID: 1295881179014-3234185.p...@n4.nabble.com
Content-Type: text/plain; charset=us-ascii


splm package is a r  implemention of spatial panel data models.
and the loglik paremeter is most important infomation for splm methods.
but  i found the loglik always been null ,it's craze to get right
estimation 
in splm with null  loglik.
Any one knows the splm package and can get the right loglik ? please
help
me.

thanks
-- 
View this message in context:
http://r.789695.n4.nabble.com/how-to-get-loglik-parameter-from-splm-pack
age-tp3234185p3234185.html
Sent from the R help mailing list archive at Nabble.com.

--- end original message -

Giovanni Millo
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 4, 
34132 Trieste (Italy)
tel. +39 040 671184 
fax  +39 040 671160 

 
Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}}

__
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] Integration of two lines

2011-01-25 Thread Xavier Robin
Hello,

I need to integrate the absolute difference between two lines measured
on different points.

# For example :
x - seq(0, 1, 1/100)
f_x - runif(101) + x
y - seq(0, 1, 1/23)
f_y - runif(24) + (1 - y)

plot(x, f_x, type=l)
lines(y, f_y)

Then I would like to compute Integral( | f_x - f_y | )dx.
(This is not the same as | Integral(f_x)dx -  Integral(f_y)dx |.)

Computing this integral looks non trivial. I guess I should interpolate
the points of f_y over x and integrate both lines on these intervals.
Even then I would miss points where the lines cross.

There are functions to integrate below *one* line (I'm thinking about
the trapz function in caTools).
Do you know if there is a function to do this integration properly with
two lines (and especially their absolute difference)?

Regards,
Xavier

__
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] Map an Area to another

2011-01-25 Thread Alaios
Dear All,
I would like to ask you help with the following:

Assume that I have an area of 36 cells (or sub-areas)
sr-matrix(data=seq(from=1,to=36),nrow=6,ncol=6,byrow=TRUE)
 sr
 [,1] [,2] [,3] [,4] [,5] [,6]
[1,]123456
[2,]789   10   11   12
[3,]   13   14   15   16   17   18
[4,]   19   20   21   22   23   24
[5,]   25   26   27   28   29   30
[6,]   31   32   33   34   35   36

This 6*6 matrix denotes an area and the contents of the cell denote the values 
the area gets inside that cell-zone (or sub-area).

I would like to map this AREA into x,y function for x e[-1,1] ye[-1,1]

I really didn't know how to implement that, so with help I got from a list 
member I tried to use FindInterval for the x,y plane. I am sure that it might 
be an easier way to do that so please do suggest it. If there is not then 
continue reading.

In the picture below: 
http://img521.imageshack.us/f/maparea.gif/
You can see the matrix presented above placed inside the x e[-1,1] ye[-1,1] 
which from now on these are the results of the f(x,y) function.
I.e f(-0.5,0.3) will return the appropriate cell (x,y) index.


As I told you I tried using the findInterval to get for the f(x,y) as an output 
the correct cell number.
This is what I have implemented so far (you can copy paste the code there is a 
small call of my function at the end):

sr.map - function(sr){
# This function converts the s(x,y) matrix into a function x spans from -1 #to 
1 and y spans from -1 to 1.
# Input: sr a x,y matrix containing the shadowing values of a Region
 breaksX - seq(from=-1, to = 1, length = nrow(sr) +1L )
 breaksY - seq(from=-1, to = 1, length = ncol(sr) + 1L)
 function(x,y){ # SPAGGETI CODE FOR EVER
 indx - findInterval(x, breaksX,rightmost.closed=TRUE)
 indy - findInterval(y, breaksY,rightmost.closed=TRUE)
  if ( (x0)  (y0) )  # x0,y0
c(indx,ncol(sr)-indy+1)
  else if ( (x0)  (y0) ) # x0,y0
c(nrow(sr)-indx+1,indy)
  else if ( (x0)  (y0) ) # x0,y0
c(nrow(sr)-indx+1,indy)
  else if ( (x0)  (y0) ) # x0,y0
c(indx,ncol(sr)-indy+1)
  else
c(indx,indy)
 }
 }

sr-matrix(data=seq(from=1,to=36),nrow=6,ncol=6,byrow=TRUE)
f.sr.map-sr.map((sr))
f.sr.map(-0.1,-0.1)


If you are worried about my so many if inside the main body of my function you 
can find why in the picture above. In the right part of the images you can see 
some of my calculations

Top right part: What I wanted to have and what was the output was when there 
was no if statement but only the last line c(indx,indy) (what two findIntervals 
returned)

Based on the what I wanted (column on the top right part) I wrote the changes 
in the logic by introducing if statements. You can find them at the bottom 
right part.
This works fine for values close to the 'borders'
f.sr.map(-1,-1)
f.sr.map(-1,1)
f.sr.map(1,-1)
f.sr.map(1,1)

but not for values for example close to zero. This is a wrong output
f.sr.map(0.1,1)
[1] 3 6

I am sure that it might be an easier way to do all that so please inform me .

I would like to thank all of you for your kind efforts to help me

Best Regards
Alex

__
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] Subtracting elements of data.frame

2011-01-25 Thread Peter Ehlers

On 2011-01-25 01:20, Vincy Pyne wrote:

Dear R helpers

I have a dataframe as

df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))


df

x   y
1  1 102
2 14 500
3  3  40
4 21 101
5 11 189

# Actually I am having dataframe having multiple columns. I am just giving an 
example.

I need to subtract all the rows of df by the first row of df i.e. I need to 
subtract each element of 'x' column by 1. Likewise I need to subtract all 
elements of column 'y' by 11. Thus I need an output like


df_new

x   y
1  0   0
2 13 398
3  2 -62
4 20  -1
5 10  87

As I had mentioned above, I have number of columns in reality and thus I can't 
use the command
  say

df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

Kindly guide


You've already had good simple solutions. Here's one more,
using the plyr package:

 require(plyr)
 df_new - colwise(.fun = function(x) {x - x[1]})(df)

plyr is very handy for all sorts of data manipulations.

Peter Ehlers



Thanking you all in advance

Regards

Vincy



[[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] Subtracting elements of data.frame

2011-01-25 Thread Henrique Dallazuanna
Try this:

sweep(as.matrix(df), 2, as.matrix(df[1,]))

On Tue, Jan 25, 2011 at 7:20 AM, Vincy Pyne vincy_p...@yahoo.ca wrote:

 Dear R helpers

 I have a dataframe as

 df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))

  df
x   y
 1  1 102
 2 14 500
 3  3  40
 4 21 101
 5 11 189

 # Actually I am having dataframe having multiple columns. I am just giving
 an example.

 I need to subtract all the rows of df by the first row of df i.e. I need to
 subtract each element of 'x' column by 1. Likewise I need to subtract all
 elements of column 'y' by 11. Thus I need an output like

  df_new
x   y
 1  0   0
 2 13 398
 3  2 -62
 4 20  -1
 5 10  87

 As I had mentioned above, I have number of columns in reality and thus I
 can't use the command
  say

 df_new = data.frame(x = df$x-df$x[1], y = df$y-df$y[1])

 Kindly guide

 Thanking you all in advance

 Regards

 Vincy



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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] Train error:: subscript out of bonds

2011-01-25 Thread Max Kuhn
What version of caret and R? We'll also need a reproducible example.


On Mon, Jan 24, 2011 at 12:44 PM, Neeti nikkiha...@gmail.com wrote:

 Hi,
 I am trying to construct a svmpoly model using the caret package (please
 see code below). Using the same data, without changing any setting, I am
 just changing the seed value. Sometimes it constructs the model
 successfully, and sometimes I get an “Error in indexes[[j]] : subscript out
 of bounds”.
 For example when I set seed to 357 following code produced result only for 8
 iterations and for 9th iteration it reaches to an error that “subscript out
 of bonds” error. I don’t understand why

 Any help would be great
 thanks
 ###
 for (i in 1:10)
  {
 fit1-NULL;
 x-NULL;
  x-which(number==i)
        trainset-d[-x,]
        testset-d[x,]
 train1-trainset[,-ncol(trainset)]
        train1-train1[,-(1)]
        test_t-testset[,-ncol(testset)]
        species_test-as.factor(testset[,ncol(testset)])
        test_t-test_t[,-(1)]
        
        #CARET::TRAIN
        

        
 fit1-train(train1,as.factor(trainset[,ncol(trainset)]),svmpoly,trControl
 = trainControl((method = cv),10,verboseIter = F),tuneLength=3)
        pred-predict(fit1,test_t)
        t_train[[i]]-table(predicted=pred,observed=testset[,ncol(testset)])
 tune_result[[i]]-fit1$results;
        tune_best-fit1$bestTune;
        scale1[i]-tune_best[[3]]
        degree[i]-tune_best[[2]]
        c1[i]-tune_best[[1]]

        }


 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Train-error-subscript-out-of-bonds-tp3234510p3234510.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.




-- 

Max

__
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] Integration of two lines

2011-01-25 Thread Rmh
g - function(x) abs(f1(x)-f2(x))

now you have one function and you can integrate it.

Rich

Sent from my iPhone

On Jan 25, 2011, at 7:32, Xavier Robin xavier.ro...@unige.ch wrote:

 Hello,
 
 I need to integrate the absolute difference between two lines measured
 on different points.
 
 # For example :
 x - seq(0, 1, 1/100)
 f_x - runif(101) + x
 y - seq(0, 1, 1/23)
 f_y - runif(24) + (1 - y)
 
 plot(x, f_x, type=l)
 lines(y, f_y)
 
 Then I would like to compute Integral( | f_x - f_y | )dx.
 (This is not the same as | Integral(f_x)dx -  Integral(f_y)dx |.)
 
 Computing this integral looks non trivial. I guess I should interpolate
 the points of f_y over x and integrate both lines on these intervals.
 Even then I would miss points where the lines cross.
 
 There are functions to integrate below *one* line (I'm thinking about
 the trapz function in caTools).
 Do you know if there is a function to do this integration properly with
 two lines (and especially their absolute difference)?
 
 Regards,
 Xavier
 
 __
 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] How to simulate a variable Xt=Wit+0.5Wit-1 with

2011-01-25 Thread Millo Giovanni
Dear Carlos,

please refrain from posting the same question umpteen times. Please
consider that code is hard to read and people might not have the time to
run your simulation etc. etc..

As I told you privately in response to your message on 18/1, 

 Re: generating correlated effects, I tried this only once, but I 
 didn't get it right. Simulations using this are, e.g., Hansen (2007) 
 http://faculty.chicagobooth.edu/christian.hansen/research/panel_cov_t.
 pdf
 and Drukker (2003)
 http://ideas.repec.org/a/tsj/stataj/v3y2003i2p168-177.html
 I suggest you take inspiration from what they did.

so the references are here for the possible benefit (?) of the list too.
In the meantime I looked at your code and it looks more or less OK to
me. I would have generated the correlated effects simply as
x_i=something random + gamma*u_i, but your Choleski approach is much
better. Sorry but a thorough check is beyond my time availability now.

arima.sim() may be a good way to go, I can't tell. The simplest way is
just to use loops: generating (in pseudo-R)

 w - runif(n, parameters)
 x[1] - random 

and then 

 for(i in 2:n) x[i] - 0.5*x[i-1]+w[i]

PS remember to generate a sufficiently long sequence of x's *before*
those in your sample, in order to make the initial conditions
irrelevant.

Let me suggest Ch. 7.1 of Kleiber and Zeileis, Applied Econometrics
with R for a nice and organized approach to (econometric) simulations
in R.
Other than this, it's just basic R, trying it out and seeing if it
works.

Best wishes,
Giovanni

--- original message ---

Message: 18
Date: Mon, 24 Jan 2011 14:38:43 +
From: car...@sapo.pt
To: r-help r-help@r-project.org
Subject: [R] How to simulate a variable Xt=Wit+0.5Wit-1 with
Wit~U(0,2)
Message-ID: 20110124143843.10742vvdq8rvq...@mail.sapo.pt
Content-Type: text/plain; charset=ISO-8859-15; DelSp=Yes;
format=flowed






Dear all

I simulate a panel data:

n - 10
t - 5
nt - n*t
pData - data.frame(id = rep(paste(JohnDoe, 1:n, sep = .), each =  
t),time = rep(1981:1985, n))
rho -0.99#simulate alphai corelated with the xi
print(rho)
alphai - rnorm(n,mean=0,sd=1)#alphai simulation
x- as.matrix(rnorm(nt,1))#xi simulation
akro - kronecker(alphai ,matrix(1,t,1))#kronecker of alphai
cormat-matrix(c(1,rho,rho,1),nrow=2,ncol=2)#correlation matrix
cormat.chold - chol(cormat)#choleski transformation of correlation
matrix
akrox - cbind(akro,x)
ax - akrox%*%cormat.chold
ai - as.matrix(ax[,1])
pData$alphai-as.vector(ai)
xcorr - as.matrix(ax[,2:(1+ncol(x))])
pData$xcorrei-as.vector(xcorr)
library(plm)
pData-plm.data(pData, index = c(id, time))
pData

But now i need a variable Xt=Wit+0.5Wit-1 with Wit~U(0,2),  the code i  
Try to use is:


for (i in 1:n) {
 p - i*t
 m - (i-1)*t+1
for (j in m:p){
 xt-arima.sim(n=nt, list(ar=c(0.5)))   }
 }
Is this the correct  way to simulate the AR(1), without the assumption  
Wit~U(0,2)? How i simulate the variable with the assumption  
Wit~U(0,2), and put it in my dataframe correctly?
Comments and tips are welcome,


regards

Carlos Br?s
Statistics Portugal-INE

-- end original message -

Giovanni Millo
Research Dept.,
Assicurazioni Generali SpA
Via Machiavelli 4, 
34132 Trieste (Italy)
tel. +39 040 671184 
fax  +39 040 671160 

 
Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:13}}

__
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] xlsReadWrite 1.5.4 and xlsReadWritePro 1.6.4 released

2011-01-25 Thread Hans-Peter Suter
The xlsReadWrite[Pro] package allows to natively read and write Excel
files (.xls) on the Win 32-bit platform.

Changes:

o fix bug with integer conversion (http://dev.swissr.org/issues/113)

  PROBLEM: values outside the integer range (i.e. 12345678901) didn't give an NA
   (and a warning message) but have been converted to a wrong value
  WHERE:
- free/pro: reading an Excel sheet and explicitely defining:
'colClasses = integer'
  or 'type = integer. It's assumed that only very few people do this.
- pro: when (auto) detecting a data.frame column type for numeric
values the type becomes
  an 'integer' in some situations. This probably affects more
people than above
  SOLUTION:
- an error will be raised for too large/small values (same as in read.table)
- numeric data.frame column types default to 'double' (as in the
free version)

o adapt RUnit tests to new behaviour
o some small cosmetic changes

Credits to Gyorgy Ottucsak who found the problem in xlsReadWritePro
and send us a report (incl. testfile). Thanks a lot!

The new xlsReadWrite version will be submitted to CRAN in a moment.
Both updated packages are available now from www.swissr.org/download
or - full listing - here:
http://dl.dropbox.com/u/2602516/swissrpkg/index.html.

Cheers,
Hans-Peter

__
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] Problem reading PostgreSQL data with RODBC

2011-01-25 Thread Albin Blaschka

Am 24.01.2011 14:08, schrieb Bart Joosen:

I think this is a problem with quotes.
If you look good, you see:

seiz.df- sqlFetch(chnl, 'source.MAIN')
...  'source.main': table not found on channel

You asked MAIN, but your db can't find main.

If you use seiz.df- sqlFetch(chnl, '\source\.\MAIN\') , you problem
should be gone.


I think the deeper problem lies with upper/lower case in the table name 
- is it MAIN, Main or main? If a tablename in PostgreSQL has at least 
one upper case, PostgreSQL uses quotes, and therefore the solution 
proposed above applies...


HTH,
Albin

--
| Albin Blaschka, Mag.rer.nat.
| Etrichstrasse 26, A-5020 Salzburg
| * www.albinblaschka.info * www.thinkanimal.info *
| - It's hard to live in the mountains, hard but not hopeless!

__
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] Integration of two lines

2011-01-25 Thread Hans W Borchers
Xavier Robin Xavier.Robin at unige.ch writes:

 Hello,
 
 I need to integrate the absolute difference between two lines measured
 on different points.
 
 # For example :
 x - seq(0, 1, 1/100)
 f_x - runif(101) + x
 y - seq(0, 1, 1/23)
 f_y - runif(24) + (1 - y)
 
 plot(x, f_x, type=l)
 lines(y, f_y)
 
 Then I would like to compute Integral( | f_x - f_y | )dx.
 (This is not the same as | Integral(f_x)dx -  Integral(f_y)dx |.)

First define a function from those points:

fx - approxfun(x, f_x)
fy - approxfun(y, f_y)
f  - function(x) abs(fx(x)-fy(x))

and now you can apply integrate() or trapz():

xx - sort(c(x, y))
yy - f(xx)
trapz(xx, yy)

trapz() should return the more accurate (i.e. exact) result.

--Hans Werner

 Computing this integral looks non trivial. I guess I should interpolate
 the points of f_y over x and integrate both lines on these intervals.
 Even then I would miss points where the lines cross.
 
 There are functions to integrate below *one* line (I'm thinking about
 the trapz function in caTools).
 Do you know if there is a function to do this integration properly with
 two lines (and especially their absolute difference)?
 
 Regards,
 Xavier
 


__
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] Integration of two lines

2011-01-25 Thread Xavier Robin
Le 25.01.2011 15:23, Rmh a écrit :
 g - function(x) abs(f1(x)-f2(x))
 
 now you have one function and you can integrate it.

Thank you Rich.

Unfortunately I have no f1 and f2 functions, only a set of observed
points on two lines - and no idea about the underlying distribution to
create a function.

Other ideas?

Xavier

__
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] Using open calais in R

2011-01-25 Thread Duncan Temple Lang
fayazvf wrote:
 
 I am using calais api in R for text analysis.
 But im facing a some problem when fetching the rdf from the server.
 I'm using the getToHost() method for the api call but i get just a null
 string.

You haven't told us nearly enough for us to be able to reproduce
what you are doing.  Where and how is the R function getToHost() ?
is it in an R package?

 The same url in browser returns an RDF document. 
 
 getToHost(www.api.opencalais.com,/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=)
 [1] 
 http://api.opencalais.com/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=;

Yes, and 
  library(RCurl)
  
getURLContent(http://api.opencalais.com/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=;)
returns  RDF content
as does
 
download.file(http://api.opencalais.com/enlighten/rest/?licenseID=dkzdggsre232ur97c6be269gcontent=HomeparamsXML=;,
eg.txt)

But since we have no way of knowing what getToHost() does (or the postToHost() 
in your earlier mail),
we cannot figure out what is happening for you.

Please do read the posting guidelines, specifically telling us about your 
session and
what packages you are using.

  D.


 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/Using-open-calais-in-R-tp3235597p3235597.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.

-- 
There are men who can think no deeper than a fact - Voltaire


Duncan Temple Langdun...@wald.ucdavis.edu
Department of Statistics  work:  (530) 752-4782
4210 Mathematical Sciences Bldg.  fax:   (530) 752-7099
One Shields Ave.
University of California at Davis
Davis, CA 95616, USA





pgpV6jduW3uDW.pgp
Description: PGP signature
__
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] Learn Vectorization (Vectorize)

2011-01-25 Thread Alaios
Greetings Friends,
I would be grateful if you can help me undestand how to make my R code more 
efficiently.

I have read in R intoductory tutorial that a for loop is not used so ofter (and 
is not maybe not that efficient) compared to other languages.

So I am trying to build understanding how to get the equivalent of a for loop 
using more R-oriented thinking.

If I got it right one way to do that in R is Vectorize. So I have writen a 
small snippet of code with two nested for loops. I would be grateful if you can 
help me find the equivalent of this code using Vectorize (or any other R 
thinking)

My code takes as input a n*m matrix and prints the x,y coordinates where a 
cells starts and ends.



remap - function (sr){
# Input this funcion takes as arguments
# sr: map
  startpos- -1 # 
  endpos- +1 # 
  stepx- (endpos - (startpos)) / nrow(sr)
  stepy- (endpos - (startpos)) / ncol(sr)

  for (i in seq(from=-1,to=1,by=stepx) ) { 
for (j in seq(from=-1,to=1,by=stepx) ){
   cat(' \n',i,j)
}
   
  }
}
sr-matrix(data=seq(from=1,to=9),nrow=3,ncol=3,byrow=TRUE)
remap(sr)

Regards
Alex

__
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] Train error:: subscript out of bonds

2011-01-25 Thread Neeti

Version:

R = 2.11.1
CARET = 4.68
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Train-error-subscript-out-of-bonds-tp3234510p3236251.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] Downloading data from internet

2011-01-25 Thread Mike Marchywka






 From: ggrothendi...@gmail.com
 Date: Mon, 24 Jan 2011 22:43:55 -0500
 To: megh700...@gmail.com
 CC: r-help@r-project.org
 Subject: Re: [R] Downloading data from internet

 On Mon, Jan 24, 2011 at 8:48 PM, Megh Dal  wrote:
  Dear all, I need to download an excel file from net, on which I have address
  like http://www.2shared.com/file/MMSMWv4B/MyData.html. Can I somehow
  directly download this file into my R workbook?
 


 If you have a direct URL to the file (not the URL in your post which
 just points a web page) then see the gdata example on this page:

 http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

Also,  try to get the problem fixed properly by contacting site
webmaster and admin ( the webmaster is unlikely to have authority himself
to do something useful and indeed may think that complicated download procedures
are cool). Tell them you are trying to load data into a computer program and 
that is
more complicated than it needs to be. This comes up a lot. Scraping html
is often difficult and unstable.




 --
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.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] crazy loop error.

2011-01-25 Thread Roy Mathew
ooh.. I have another question.
What if I want to add the value in the vector a to the hello each time it
prints.
Here is your output

a - c(2,3,5,5,5,6,6,7)
mapply(rep, hello, rle(a)$lengths, USE.NAMES = FALSE)

[[1]]
[1] hello

[[2]]
[1] hello

[[3]]
[1] hello hello hello

[[4]]
[1] hello hello

[[5]]
[1] hello

If I want something like this, based on values in vector a.

[[1]]
[1] hello 2

[[2]]
[1] hello 3

[[3]]
[1] hello 5 hello 5 hello 5

[[4]]
[1] hello 6 hello 6

[[5]]
[1] hello 7

What i am actually doing is hmm.. I have a bunch of text files which is
output from another program. I want to extract some specific information
from these files and write to a new file and save it.
All these files have a certain variable k which maybe 2, or 3 or 5 etc. The
vector a shows the k values of 8 of such files. I want the contents of all
files with k value 5 to be written into one file.

Thanks,
Roy



On Mon, Jan 24, 2011 at 11:43 PM, Erik Iverson er...@ccbr.umn.edu wrote:



 Roy Mathew wrote:

 Thanks for the reply Erik, As you mentioned, grouping consecutive elements
 of 'a' was my idea. I am unaware of any R'ish way to do it. It would be nice
 if someone in the community knows this.


 Is this the idea you're trying to execute?  It uses ?rle and ?mapply.


 a - c(2,3,5,5,5,6,6,7)
 mapply(rep, hello, rle(a)$lengths, USE.NAMES = FALSE)

 [[1]]
 [1] hello

 [[2]]
 [1] hello

 [[3]]
 [1] hello hello hello

 [[4]]
 [1] hello hello

 [[5]]
 [1] hello




-- 
Best Regards,
Roy

[[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] Problem with matchit() and zelig()

2011-01-25 Thread F.Giammarino
Dear all,

Does anybody know why the following code returns an error message?

library(MatchIt)
library(Zelig)
data(lalonde)

m.out1-matchit(treat~age+educ+black+hispan+nodegree+married
+re74+re75, method=full, data=lalonde)

z.out1-zelig(re78~age+educ+black+hispan+nodegree+married+re74+re75,
data=match.data(m.out1, control), model=ls , weights=weights )

x.out1-setx(z.out1, data=match.data(m.out1, treat), cond=T )

s.out1-sim(z.out1, x=x.out1)

Error in model.frame.default(formula = re78 ~ age + educ + black +
hispan +  : 
  variable lengths differ (found for '(weights)')


I noticed that the problem disappears if either the option
weights=weights in the zelig() function or the option cond=T in the
setx() function is removed. 

Is there a conflict between the options weights=weights in zelig() and
cond=T in setx()/sim()?

Or is there an inconsistency in my syntax? 

Any suggestion would be very much appreciated. 

Best wishes, 
Flavia Giammarino
London School of Economics, UK 





Please access the attached hyperlink for an important electronic communications 
disclaimer: http://lse.ac.uk/emailDisclaimer

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

2011-01-25 Thread vioravis

I am trying to do binning on three variables (3d binning). The bin boundaries
are specified by the user separately for each variable. I used the bin2
function in the 'ash' package for 2d binning that involves only two
variables but didn't any package for similar binning with three variables.
Are there any packages or codes available for 3d binning?? Thank you. 
 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/3D-Binning-tp3236223p3236223.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] Paired data survival analysis

2011-01-25 Thread Terry Therneau
--- begin included message ---

Im an honours student at Monash University. I'm trying to analyse some
data for my project, which involved 2 treatments. My subjects were
exposed to both treatments, and i gave them 60 minutes to perform a
certain behaviour.  3 of my subjects performed the behaviour in one
treatment but not the other. Therefore, i need to do a survival
analysis using paired data. Im little confused about how to go about
this in R. Im able to perfrom a normal surival analyses not taking the
paired data into account, but im just wondering if there is some way
to take the pairing into account. I know there are 3 different ways to
deal with grouping in the survival package, strata, cluster and
frailty but i struggle to understand the meaning of these arguments
and therefore do not know which one to use (if any).

--- end inclusion ---

All 3 methods can be defended.  Adding cluster(id) to the model is
equivalent to a generalized estimating equations approach (if this were
a glm) or to the variance estimates commonly used in survey sampling (if
this were a linear model).  Adding frailty(id) is equivalent to fitting
a linear mixed model.  Using strata corresponds to a matched-pair
analysis, and will essentially reduce to a sign test: for each subject
treatment A was better, B was better, or tied.  It's overkill in this
case (lower power).
   If this were a linear model, you could find strong advocates for
either the GEE and mixed approach being better.  I somewhat prefer the
GEE method myself.  

Terry T.

__
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] Learn Vectorization (Vectorize)

2011-01-25 Thread Henrique Dallazuanna
Try this:

expand.grid(seq(startpos, endpos, by = diff(c(startpos, endpos)) /
nrow(sr)),
  seq(startpos, endpos, by = diff(c(startpos, endpos)) / nrow(sr)))

On Tue, Jan 25, 2011 at 1:29 PM, Alaios ala...@yahoo.com wrote:

 Greetings Friends,
 I would be grateful if you can help me undestand how to make my R code more
 efficiently.

 I have read in R intoductory tutorial that a for loop is not used so ofter
 (and is not maybe not that efficient) compared to other languages.

 So I am trying to build understanding how to get the equivalent of a for
 loop using more R-oriented thinking.

 If I got it right one way to do that in R is Vectorize. So I have writen a
 small snippet of code with two nested for loops. I would be grateful if you
 can help me find the equivalent of this code using Vectorize (or any other R
 thinking)

 My code takes as input a n*m matrix and prints the x,y coordinates where a
 cells starts and ends.



 remap - function (sr){
 # Input this funcion takes as arguments
 # sr: map
  startpos- -1 #
  endpos- +1 #
  stepx- (endpos - (startpos)) / nrow(sr)
  stepy- (endpos - (startpos)) / ncol(sr)

  for (i in seq(from=-1,to=1,by=stepx) ) {
for (j in seq(from=-1,to=1,by=stepx) ){
   cat(' \n',i,j)
}

  }
 }
 sr-matrix(data=seq(from=1,to=9),nrow=3,ncol=3,byrow=TRUE)
 remap(sr)

 Regards
 Alex

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] Extracting SSE from lm

2011-01-25 Thread Brian J Mingus
Apologies for this simple question -

Given the number of comparisons I need to do it has become somewhat
laborious to compute the SSE manually. I first have to extract the
coefficients, build the model and run the model on the data. So far I
haven't found any method in R that will do this for me. Is there a method
that I haven't seen, or is there a small function I could write that would
do this, and how might I go about that?

Thanks,

Brian

[[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] deSolve: Problem solving ODE including modulo-operator

2011-01-25 Thread apokaly

I have a problem integrating the 'standard map' (
http://en.wikipedia.org/wiki/Standard_map
http://en.wikipedia.org/wiki/Standard_map ) with deSolve:

By using the modulo-operator '%%' with 2*pi in the ODEs (standardmap1), the
resulting values of P and Theta, should not be greater than 2pi. Because
this was not the case, i was thinking that the function 'ode' has some
internal problems with the '%%' or integrating periodical ODEs, so I wrote a
modulo-function by myself (modulo and standardmap2). But still I get values
much higher than 2pi and I cannot find the error... Any guess?

Thanks


Full code:

library(deSolve)


iterations - 100

Parameter - c(k = 0.6)
State - c(Theta = 1 ,  P = 1) 

Time - 0:iterations/10




standardmap1 - function(Time, State, Parameter){ 
  with(as.list(c(State, Parameter)), {
dP  - (P + k * sin(Theta)) %% (2 * pi)
dTheta - (P + Theta) %% (2 * pi)
return(list(c(dP, dTheta)))
})
}

#solve ode using standardmap1
out1 - as.data.frame(ode(func = standardmap1, y = State,parms = Parameter,
times = Time))




# x mod y, end: maximal iterations
modulo - function(x,y,end=1000){
for (n in 0:end)
if (x  (n-1)*y) 
z = x - (n-1)*y
if (z  0)
return(z)
else break
}



standardmap2 - function(Time, State, Parameter){
  with(as.list(c(State, Parameter)), {
dTheta - modulo((P + Theta),(2*pi))
dP - modulo(P + k *sin(Theta),(2*pi))
return(list(c(dP, dTheta)))
})
}



#solve ode using standardmap2
out2 - as.data.frame(ode(func = standardmap2, y = State,parms = Parameter,
times = Time))

#plot the results
matplot(out1[2],out1[3], type = p, pch = .)
matplot(out2[2],out2[3], type = p, pch = .)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/deSolve-Problem-solving-ODE-including-modulo-operator-tp3236396p3236396.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] barplot with varaible-width bars

2011-01-25 Thread Gould, A. Lawrence
I would like to produce a bar plot with varying-width bars.  Here is an example 
to illustrate:

ww - c(417,153,0.0216,0.0065,556,256,0.0162,0.0117,
+  726,379,0.0358,0.0501,786,502,0.0496,0.0837,
+  892,591,0.0785,0.0795)
yy-t(t(array(ww,c(2,10

barplot(yy[,2*1:5],las=1,space=c(.1,.5),beside=T)

produces a barplot of 5 pairs of bars that are of equal width

barplot(yy[,2*1:5],las=1,width=c(yy[,(2*1:5)-1]),space=c(.1,.5),beside=T)

makes the bars in each pair of unequal width, but the two widths do not vary 
from pair to pair

I would like the width of each bar to be proportional to its corresponding 
value in the width statement of this last call of barplot, like what I think 
could be done with the mulbar function of SPlus.  Can I do this with barplot 
itself, or is this something for which lattice or ggplot 2 is needed?  And, if 
so, what would typical code look like?

Thanks for your help.

Larry Gould


Notice:  This e-mail message, together with any attachme...{{dropped:14}}

__
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] crazy loop error.

2011-01-25 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 25.01.2011 10:58:36:

 ooh.. I have another question.
 What if I want to add the value in the vector a to the hello each time 
it
 prints.
 Here is your output
 
 a - c(2,3,5,5,5,6,6,7)
 mapply(rep, hello, rle(a)$lengths, USE.NAMES = FALSE)
 
 [[1]]
 [1] hello
 
 [[2]]
 [1] hello
 
 [[3]]
 [1] hello hello hello
 
 [[4]]
 [1] hello hello
 
 [[5]]
 [1] hello
 
 If I want something like this, based on values in vector a.

Not sure how to use mapply

test-vector(list, 5)
lll-rle(a)
for (i in seq_along(lll$lengths)) test[[i]] - rep(paste(hello, 
lll$values[i]), lll$lengths[i])


 
 [[1]]
 [1] hello 2
 
 [[2]]
 [1] hello 3
 
 [[3]]
 [1] hello 5 hello 5 hello 5
 
 [[4]]
 [1] hello 6 hello 6
 
 [[5]]
 [1] hello 7
 
 What i am actually doing is hmm.. I have a bunch of text files which is
 output from another program. I want to extract some specific information
 from these files and write to a new file and save it.
 All these files have a certain variable k which maybe 2, or 3 or 5 etc. 
The
 vector a shows the k values of 8 of such files. I want the contents of 
all
 files with k value 5 to be written into one file.

That is rather vague description. Does those files have some structure? 
How do you know the variable k?

Loops are not so ineffective if you use them for what they are good and if 
you do not expand the object within loop. See R-Inferno from P.Burns.

Regards
Petr




 
 Thanks,
 Roy
 
 
 
 On Mon, Jan 24, 2011 at 11:43 PM, Erik Iverson er...@ccbr.umn.edu 
wrote:
 
 
 
  Roy Mathew wrote:
 
  Thanks for the reply Erik, As you mentioned, grouping consecutive 
elements
  of 'a' was my idea. I am unaware of any R'ish way to do it. It would 
be nice
  if someone in the community knows this.
 
 
  Is this the idea you're trying to execute?  It uses ?rle and ?mapply.
 
 
  a - c(2,3,5,5,5,6,6,7)
  mapply(rep, hello, rle(a)$lengths, USE.NAMES = FALSE)
 
  [[1]]
  [1] hello
 
  [[2]]
  [1] hello
 
  [[3]]
  [1] hello hello hello
 
  [[4]]
  [1] hello hello
 
  [[5]]
  [1] hello
 
 
 
 
 -- 
 Best Regards,
 Roy
 
[[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] applying a function to output a matrix

2011-01-25 Thread Lara Poplarski
Dear List,

I am using function distCosine from package geosphere to a list of lat/lon
coordinates, and I want to calculate the great circle distance between a
pair of coordinates in the list and all other pairs --- essentially, the
output should be a matrix. I have been able to achieve this with two nested
loops, as in the example below, but this is rather slow. Can someone please
suggest how to do this with apply or similar?

Many thanks,
Lara


install.packages(geosphere)

library(geosphere)


##generate sets of random points

n   - 100

lon - runif(n, -180, 180)

lat - runif(n, -90, 90)


#package geosphere

##spherical law of cosines method

dCos - matrix( , nrow = length(lon), ncol = length(lat))

for (i in 1:length(lon)) {

  for (j in 1:length(lat)) {

dCos[[i,j]] - distCosine(matrix(c(lon[i], lat[i]), ncol=2), matrix(c(
lon[j], lat[j]), ncol=2))

}}

[[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] crazy loop error.

2011-01-25 Thread Bert Gunter
Well, I'm not Prof. Ripley, but the answer is: Look at the code.
seq_len, seq.int, and seq_along call Primitives, which are implemented
in C, and therefore MUCH faster than seq(), which is implemented as
pure R code (and is also a generic, so requires method dispatch).
Though for small n (up to a few thousand, say), it probably doesn't
make much difference.(Here, to be corrected by Prof. Ripley is
needed).

-- Bert

On Tue, Jan 25, 2011 at 2:22 AM, Ivan Calandra
ivan.calan...@uni-hamburg.de wrote:
 Mr Ripley,

 May I ask why seq_len() and seq_along() are better than seq()?

 Thanks,
 Ivan

 Le 1/25/2011 09:58, Prof Brian Ripley a écrit :

 On Tue, 25 Jan 2011, Petr Savicky wrote:

 On Mon, Jan 24, 2011 at 11:18:35PM +0100, Roy Mathew wrote:

 Thanks for the reply Erik, As you mentioned, grouping consecutive
 elements
 of 'a' was my idea.
 I am unaware of any R'ish way to do it. It would be nice if someone in
 the
 community knows this.

 The error resulting in the NA was pretty easy to fix, and my loop works,
 but
 the results are still wrong (new script below).
 Ideally it should print single hello for the single letters and
 grouped '3
 hellos' for the fives, grouped '2 hellos' for the sixes etc.

 Based on the run results, if the value of n is being tracked, it changes
 quite unpredictably.
 Can someone explain how the value of n changes from end of the loop to
 the
 top without anything being done to it?

 Hi.

 A for-loop in R is different from a for-loop in C. It is similar
 to foreach loop in Perl. If v is a vector, then

  for (n in v)

 first creates the vector v and then always performs length(v) iterations.
 Before iteration i, n is assigned v[i] even if n is changed in the
 previous iteration.

 And also if v is changed during the loop.

 If you want to control the loop variable during execution, it is possible
 to use a while loop, where you have full control. While loop may be
 better
 also if v has a very large length, since, for example

  for (n in 1:100)

 creates a vector of length 100 in memory.

 It should also be noted that the for-loop

  for (n in 1:k)

 performs 2 iterations, if k is 0, since 1:0 is a vector of length 2.
 If k may be 0, then it is better to use

  for (n in seq(length=k))

 since seq(length=0) has length 0.

 Since you keep mentioning that, it is actually much better to use
 seq_len(k) (and seq_along(x) instead of your earlier recommendation of
 seq(along=x)).  And if you are using seq() in other cases in programs,
 consider seq.int() instead.

 Hope this helps.

 Petr Savicky.


 --
 Ivan CALANDRA
 PhD Student
 University of Hamburg
 Biozentrum Grindel und Zoologisches Museum
 Abt. Säugetiere
 Martin-Luther-King-Platz 3
 D-20146 Hamburg, GERMANY
 +49(0)40 42838 6231
 ivan.calan...@uni-hamburg.de

 **
 http://www.for771.uni-bonn.de
 http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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




-- 
Bert Gunter
Genentech Nonclinical Biostatistics

__
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] Multivariate polynomials Howto

2011-01-25 Thread Alaios
Good Evening,
I would like to work with multivariate polynomials (x and y variables).
I know that there is a package called multipol but I am not sure that supports 
my needs.

I use a function (in reality legendre.polynomials) which creates me the 
polynomials I want.
For example the following returns
 legendre.polynomials(2)[[2]]
x  (first order polynomial)

I would like to calculate the polynomials with variable x with the polynomials 
with variable y. I do not know how I can do that in R as my function always 
returns output with x. Is it possible to change variable x with y?

Regards
Alex

__
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] Learn Vectorization (Vectorize)

2011-01-25 Thread Bert Gunter
Inline below.

-- Bert

On Tue, Jan 25, 2011 at 7:48 AM, Henrique Dallazuanna www...@gmail.com wrote:
 Try this:

 expand.grid(seq(startpos, endpos, by = diff(c(startpos, endpos)) /
 nrow(sr)),
          seq(startpos, endpos, by = diff(c(startpos, endpos)) / nrow(sr)))

 On Tue, Jan 25, 2011 at 1:29 PM, Alaios ala...@yahoo.com wrote:

 Greetings Friends,
 I would be grateful if you can help me undestand how to make my R code more
 efficiently.

 I have read in R intoductory tutorial that a for loop is not used so ofter
 (and is not maybe not that efficient) compared to other languages.

 So I am trying to build understanding how to get the equivalent of a for
 loop using more R-oriented thinking.

 If I got it right one way to do that in R is Vectorize.

-- You got it wrong. Vectorize() is just another (disguised) way of
doing R level looping, via apply functions.It offers no efficiency
advantage over explicit for loops, though it may make for cleaner
programming, which IS a great advantage in the bigger scheme of
things, I admit. But thatwasn't your question.

The basic idea of vectorization in R is to use **built-in** commands
that act on whole objects through their internal (usually C) code.
These **will** be much faster than looping in R.

So for example to generate 10 random numbers one can do:

 system.time(x -rnorm(1e5))
   user  system elapsed
   0.020.000.02


## OR

 system.time({
+   y - numeric(1e5)
+   for(i in 1:(1e5))y[i] - rnorm(1)
+   })
   user  system elapsed
   0.860.010.87


The former is vectorized, producing all 10 randoms at a go and
runs 40 times faster than the latter, which is not, instead producing
one random number at a time (and requiring the overhead of a separate
call for each, I think).

Please read an Intro to R for more. VR's MASS also has some helpful
remarks on vectorization. I'm sure that other texts (e.g. Dalgaard's)
are worth consulting on this, too, but I haven't read them.

-




 So I have writen a
 small snippet of code with two nested for loops. I would be grateful if you
 can help me find the equivalent of this code using Vectorize (or any other R
 thinking)

 My code takes as input a n*m matrix and prints the x,y coordinates where a
 cells starts and ends.



 remap - function (sr){
 # Input this funcion takes as arguments
 # sr: map
  startpos- -1 #
  endpos- +1 #
  stepx- (endpos - (startpos)) / nrow(sr)
  stepy- (endpos - (startpos)) / ncol(sr)

  for (i in seq(from=-1,to=1,by=stepx) ) {
    for (j in seq(from=-1,to=1,by=stepx) ){
       cat(' \n',i,j)
    }

  }
 }
 sr-matrix(data=seq(from=1,to=9),nrow=3,ncol=3,byrow=TRUE)
 remap(sr)

 Regards
 Alex

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




 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O

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





-- 
Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://devo.gene.com/groups/devo/depts/ncb/home.shtml

__
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] ggplot - controlling point size

2011-01-25 Thread Gene Leynes
Can anyone illuminate the following for me?
How can I get rid of the blue line in the key in the second plot?

## Create a simple data frame
df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000),
type=sample(letters[1:2],1000, replace=TRUE))

## Very nice!  Almost what I want
qplot(x, y, data=df, colour=factor(type)) + geom_smooth()

## Make a nicer plot, with smaller points
## but why does that add the little blue line with a 1?
qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth()

[[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] Failing to install {rggobi} on win-7 R 2.12.0

2011-01-25 Thread Tal Galili
Greetings all,

I am failing to install the package rggobi on windows 7 with R 2.12.0.
On R 2.11.1, the package was installed fine.

I asked for help on the rggobi google group 4 days ago, and didn't receive
any help, so I was wondering if someone here might have a suggestion.

Here are the details:

---


I am having a similar (bot not exact) problem as Tom had here:
http://groups.google.com/group/ggobi/browse_thread/thread/67b7260d074d710c

I downloaded and installed all components. (GTK was placed in d:\\GTK)

When I try to load the rggobi library (library(rggobi) it offers me to
install GTK+ because it can't find the dll (even that all of
the dll it is looking for are present in the path environment
Sys.getenv(PATH)
Sys.getenv(GTK_BASEPATH)
)

When answering no to the installation of GTK, I get the following
error in a popping window:
the procedure entry point g_malloc_n could not be located in the
dynamic link library libglic-2.0-0.dll

I then get the following errors in the R console:
Loading required package: rggobi
Error in library.dynam(RGtk2, pkgname, libname) :
 DLL 'RGtk2' not found: maybe not installed for this architecture?
Failed to load RGtk2 dynamic library, attempting to install it.
Learn more about GTK+ at http://www.gtk.org
If the package still does not load, please ensure that GTK+ is
installed and that it is on your PATH environment variable
IN ANY CASE, RESTART R BEFORE TRYING TO LOAD THE PACKAGE AGAIN
Error in inDL(x, as.logical(local), as.logical(now), ...) :
 unable to load shared object 'd:/Program Files/R/library/rggobi/libs/
i386/rggobi.dll':
 LoadLibrary failure:  The specified procedure could not be found.



I also tried running R as an administrator, but it didn't fix the
problem (only added another error popup window with the massage:
the procedure entry point cairo_glyph_allocate could not be located
in the dynamic link library libcairo-2.dll)


Here is my sessionInfo:
 sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255
[3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C
[5] LC_TIME=Hebrew_Israel.1255

attached base packages:
[1] stats graphics  grDevices utils datasets  methods
base







Thank you for any advice.

Best,
Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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] NA replacing

2011-01-25 Thread andrija djurovic
Hello R user,

I have following data frame:

df=data.frame(id=c(1:10),strata=rep(c(1,2),c(5,5)),y=c(
10,12,10,NA,15,70,NA,NA,55,100),x=c(3,4,5,7,4,10,12,8,3,15))

and I would like to replace NA's with:

instead of first NA  tapply(na.exclude(df)$y,na.exclude(df)$strata,sum)[1]*
*7 */tapply(na.exclude(df)$x,na.exclude(df)$strata,sum)[1]
where 7 is the value of x (id=4) in strata 1 where y=NA

instead of second NA tapply(na.exclude(df)$y,na.exclude(df)$strata,sum)[2]*
*12 */tapply(na.exclude(df)$x,na.exclude(df)$strata,sum)[2]
where 12 is the value of x (id=7) in strata 2 where y=NA

instead of third NA tapply(na.exclude(df)$y,na.exclude(df)$strata,sum)[2]* *
8 */tapply(na.exclude(df)$x,na.exclude(df)$strata,sum)[2]
where 8 is the value of x(id=8) in strata 2 where y=NA.

So, I would like to replace NA inside the stratas on above explained way.

Does anyone know how to do this?

thanks in advance

Andrija

[[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] ggplot - controlling point size

2011-01-25 Thread Felipe Carrillo
try this:
qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth()
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx




- Original Message 
 From: Gene Leynes gleyne...@gmail.com
 To: r-help@r-project.org
 Sent: Tue, January 25, 2011 9:28:20 AM
 Subject: [R] ggplot - controlling point size
 
 Can anyone illuminate the following for me?
 How can I get rid of the blue line in the key in the second plot?
 
 ## Create a simple data frame
 df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000),
         type=sample(letters[1:2],1000, replace=TRUE))
 
 ## Very nice!  Almost what I want
 qplot(x, y, data=df, colour=factor(type)) + geom_smooth()
 
 ## Make a nicer plot, with smaller points
 ## but why does that add the little blue line with a 1?
 qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth()
 
     [[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] Train error:: subscript out of bonds

2011-01-25 Thread Neeti

after using options(error=utils::recover) option, following is the output. if
i am correct this means that in ksvm there is some problem, but really could
not understand. could anyone please tell me what is wrong...

any help will be great 

thank you so much..


Enter a frame number, or 0 to exit   

 1: train(train1, as.factor(trainset[, ncol(trainset)]), svmpoly,
trControl = trainControl((method = cv), 10,
 2: train.default(train1, as.factor(trainset[, ncol(trainset)]), svmpoly,
trControl = trainControl((method = c
 3: do.call(trControl$computeFunction, argList)
 4: function (X, FUN, ...) 
 5: FUN(X[[25]], ...)
 6: do.call(createModel, args)
 7: function (data, method, tuneValue, obsLevels, pp = NULL, ...) 
 8: ksvm(as.matrix(trainX), trainY, kernel = polydot(degree =
tuneValue$.degree, scale = tuneValue$.scale, offset
 9: ksvm(as.matrix(trainX), trainY, kernel = polydot(degree =
tuneValue$.degree, scale = tuneValue$.scale, offset
10: .local(x, ...)
11: ksvm(x[c(indexes[[i]], indexes[[j]]), , drop = FALSE][cind, ], yd[cind],
type = type(ret), kernel = kernel, k
12: ksvm(x[c(indexes[[i]], indexes[[j]]), , drop = FALSE][cind, ], yd[cind],
type = type(ret), kernel = kernel, k
13: .local(x, ...)

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Train-error-subscript-out-of-bonds-tp3234510p3236494.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] determining the order in which points are plotted

2011-01-25 Thread Greg Snow
With large numbers of points you might want to consider hexagonal binning 
instead of scatter plots.  I don't know of any tools that both do the binning 
and take groups into account, but you could think it through and work something 
out.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Mike Miller
 Sent: Monday, January 24, 2011 5:39 PM
 To: David Winsemius
 Cc: R-Help List
 Subject: Re: [R] determining the order in which points are plotted
 
 On Mon, 24 Jan 2011, David Winsemius wrote:
 
  On Jan 24, 2011, at 6:49 PM, Mike Miller wrote:
 
  I make plenty of scatterplots, especially using scatterplot.matrix
 from
  library(car).  One thing I don't know how to do is determine which
  points are plotted last.  Sometimes I plot a large number of points
 for
  multiple groups represented by different colors.
 
  ?points
 
 
 Thanks for the tip.  I guess I would make vectors for x, y and col in
 the
 desired order and the first elements would be plotted first:
 
 Graphical parameters ‘pch’, ‘col’, ‘bg’, ‘cex’ and ‘lwd’ can be
 vectors (which will be recycled as needed) giving a value for each
 point plotted.  If lines are to be plotted (e.g. for ‘type = b’/
 the first element of ‘lwd’ is used.
 
 Suppose I'm plotting 10,000 points in a 10 x 10 scatterplot matrix
 (roughly what I'm actually doing).  That's a total of 1 million points.
 It might take a while, but I can wait.  However, I'm not sure how to
 get
 the coordinates right for additional points in a scatterplot matrix.
 Maybe I need to study that source code.
 
 I did figure out recently how to use transparent points to get the axes
 right.  Color #ff00 does that trick for me -- that's white color
 with zero opaqueness, full transparency.
 
 Mike
 
 --
 Michael B. Miller, Ph.D.
 Minnesota Center for Twin and Family Research
 Department of Psychology
 University of Minnesota

__
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] coxme and random factors

2011-01-25 Thread Sophie Armitage
Hi

I would really appreciate some help with my code for coxme...

My data set
I'm interested in survival of animals after an experiment with 4  
treatments, which was performed on males and females. I also have two  
random factors:

Response variable:  survival (death)
Factor 1:   treatment (4 levels)
Factor 2:   sex (male / female)
Random effects 1:   person nested within day (2 people did the  
experiment over 2   days)
Random effects 2:   box nested within treatment (animals were kept in  
boxes in groups of 6, and there were multiple boxes per treatment)

I've read the introductions to coxme by Terry Therneau, and something  
like the following is what I think I should use:

model1-coxme(Surv(death,censor)~treatment*sex+(1|day/person)+(1| 
treatment/box))

Which gives me the following:
Cox mixed-effects model fit by maximum likelihood

   events, n = 154, 291
   Iterations= 57 305
NULL Integrated Penalized
Log-likelihood -823.276  -795.2354 -784.4807

Chisq   df  p   
AIC   BIC
Integrated loglik   56.08   11.00   4.9096e-08   34.08   0.67
  Penalized loglik  77.59   17.91   2.0958e-09  41.78 -12.60

Model:  Surv(death, censor) ~ treatment * sex + (1 | day/person) + (1  
|  treatment/box)
Fixed coefficients
coef
exp(coef)   se(coef)
zp
teratmentb  -0.0838877 0.9195345 0.3744511 
-0.22 0.8200
treatmentb2 -0.4731922 0.6230103 0.3136199 -1.51 
0.1300
treatmentn  -1.0154149 0.3622521 0.4097754 
-2.48 0.0130
sexmale -0.1838885 0.8320286 0.2602169 
-0.71 0.4800
treatmentb:sexmale  -0.3905856 0.6766605 0.2132936 -1.83 
0.0670
treatmentb2:sexmale 0.6742202 1.9625020 0.3836907  1.76 0.0790
treatmentn:sexmale  1.2628977 3.5356520 0.4603589  2.74 
0.0061

Random effects
  Group VariableStd Dev Variance
  day/person(Intercept) 0.32690104  0.10686429
  day   (Intercept) 0.49516113  0.24518455
  treatment/box (Intercept) 0.26837158  0.07202330
  treatment (Intercept) 0.29263637  0.08563604


My questions
(1) Does anyone know how I can test the significance of each of the  
random effects in turn? For example, to find the significance of (1| 
treatment/box) can I compare the results of the above model to one  
without this term? (i.e. by subtracting the integrated loglikelihood  
values of the model without (1|treatment/box) from the model with  
that term).

(2) Can I include 'treatment' as a factor as well as including it as  
part of a nested term? (incidentally I did wonder if I should include  
it as (treatment|box), but an error message comes back that factors  
cannot be used as a covariate within a random effect)

(3) Is it possible to test the proportionality assumption within  
coxme. Previously I used  cox.zph(model1) with coxph, but that does  
not work with coxme.

Very many thanks to anyone who can offer me some advice!

Sophie


[[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] crazy loop error.

2011-01-25 Thread Ivan Calandra
Now I understand what the difference between a primitive and a 
non-primitive!

Thanks for the clarification!
Ivan

Le 1/25/2011 18:03, Bert Gunter a écrit :

Well, I'm not Prof. Ripley, but the answer is: Look at the code.
seq_len, seq.int, and seq_along call Primitives, which are implemented
in C, and therefore MUCH faster than seq(), which is implemented as
pure R code (and is also a generic, so requires method dispatch).
Though for small n (up to a few thousand, say), it probably doesn't
make much difference.(Here, to be corrected by Prof. Ripley is
needed).

-- Bert

On Tue, Jan 25, 2011 at 2:22 AM, Ivan Calandra
ivan.calan...@uni-hamburg.de  wrote:

Mr Ripley,

May I ask why seq_len() and seq_along() are better than seq()?

Thanks,
Ivan

Le 1/25/2011 09:58, Prof Brian Ripley a écrit :

On Tue, 25 Jan 2011, Petr Savicky wrote:


On Mon, Jan 24, 2011 at 11:18:35PM +0100, Roy Mathew wrote:

Thanks for the reply Erik, As you mentioned, grouping consecutive
elements
of 'a' was my idea.
I am unaware of any R'ish way to do it. It would be nice if someone in
the
community knows this.

The error resulting in the NA was pretty easy to fix, and my loop works,
but
the results are still wrong (new script below).
Ideally it should print single hello for the single letters and
grouped '3
hellos' for the fives, grouped '2 hellos' for the sixes etc.

Based on the run results, if the value of n is being tracked, it changes
quite unpredictably.
Can someone explain how the value of n changes from end of the loop to
the
top without anything being done to it?

Hi.

A for-loop in R is different from a for-loop in C. It is similar
to foreach loop in Perl. If v is a vector, then

  for (n in v)

first creates the vector v and then always performs length(v) iterations.
Before iteration i, n is assigned v[i] even if n is changed in the
previous iteration.

And also if v is changed during the loop.


If you want to control the loop variable during execution, it is possible
to use a while loop, where you have full control. While loop may be
better
also if v has a very large length, since, for example

  for (n in 1:100)

creates a vector of length 100 in memory.

It should also be noted that the for-loop

  for (n in 1:k)

performs 2 iterations, if k is 0, since 1:0 is a vector of length 2.
If k may be 0, then it is better to use

  for (n in seq(length=k))

since seq(length=0) has length 0.

Since you keep mentioning that, it is actually much better to use
seq_len(k) (and seq_along(x) instead of your earlier recommendation of
seq(along=x)).  And if you are using seq() in other cases in programs,
consider seq.int() instead.


Hope this helps.

Petr Savicky.

--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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






--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

__
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] ggplot - controlling point size

2011-01-25 Thread Brian Diggs

On 1/25/2011 9:44 AM, Felipe Carrillo wrote:

try this:
qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth()


Felipe very nicely answered the how of your question.  I thought I'd 
followup with the why.


Using qplot, it assumes that you are giving a set of aesthetic mappings. 
 As such, size is being mapped to a variable that is 1 for all entries. 
 Then, in the usual way, a mapping is created between values of the 
variable in the data space and in the aesthetic space (actual sizes) and 
a legend is created to display this mapping.  Enclosing the 1 in an I() 
indicates that you are giving a literal value to set the aesthetic to, 
in which case no mapping between aesthetic and data space (nor legend) 
is needed.


Alternatively, you can use an identity scale to state that the data and 
aesthetic spaces are the same, and tell it to not plot the legend.


qplot(x, y, data=df, colour=factor(type), size=1) +
geom_smooth() +
scale_size_identity(legend=FALSE)

The distinction between aesthetic mapping and setting is even more 
evident in ggplot notation:


ggplot(df, aes(x=x, y=y, colour=factor(type))) +
geom_point(size=1) +
geom_smooth()



Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish  Wildlife Service
California, USA
http://www.fws.gov/redbluff/rbdd_jsmp.aspx




- Original Message 

From: Gene Leynesgleyne...@gmail.com
To: r-help@r-project.org
Sent: Tue, January 25, 2011 9:28:20 AM
Subject: [R] ggplot - controlling point size

Can anyone illuminate the following for me?
How can I get rid of the blue line in the key in the second plot?

## Create a simple data frame
df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000),
 type=sample(letters[1:2],1000, replace=TRUE))

## Very nice!  Almost what I want
qplot(x, y, data=df, colour=factor(type)) + geom_smooth()

## Make a nicer plot, with smaller points
## but why does that add the little blue line with a 1?
qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth()


--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health  Science University

__
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] ggplot - controlling point size

2011-01-25 Thread Gene Leynes
Thank you both, very much.

Using the identity function I() is a very nice trick, but it still feels
like a trick.

Using ggplot makes the most sense to me.
ggplot(df, aes(x=x, y=y, colour=factor(type))) +
   geom_point(size=1) +
   geom_smooth()

Thank you very much for taking the time to explain the syntax.

I had tried using the ggplot function, but I couldn't figure out how to
handle thecolour=factor(type) part.
(my erroneous formulas are omitted for clarity)

On Tue, Jan 25, 2011 at 12:06 PM, Brian Diggs dig...@ohsu.edu wrote:

 On 1/25/2011 9:44 AM, Felipe Carrillo wrote:

 try this:
 qplot(x, y, data=df, colour=factor(type), size=I(1)) + geom_smooth()


 Felipe very nicely answered the how of your question.  I thought I'd
 followup with the why.

 Using qplot, it assumes that you are giving a set of aesthetic mappings.
  As such, size is being mapped to a variable that is 1 for all entries.
  Then, in the usual way, a mapping is created between values of the variable
 in the data space and in the aesthetic space (actual sizes) and a legend is
 created to display this mapping.  Enclosing the 1 in an I() indicates that
 you are giving a literal value to set the aesthetic to, in which case no
 mapping between aesthetic and data space (nor legend) is needed.

 Alternatively, you can use an identity scale to state that the data and
 aesthetic spaces are the same, and tell it to not plot the legend.


 qplot(x, y, data=df, colour=factor(type), size=1) +
geom_smooth() +
scale_size_identity(legend=FALSE)

 The distinction between aesthetic mapping and setting is even more evident
 in ggplot notation:

 ggplot(df, aes(x=x, y=y, colour=factor(type))) +
geom_point(size=1) +

geom_smooth()


  Felipe D. Carrillo
 Supervisory Fishery Biologist
 Department of the Interior
 US Fish  Wildlife Service
 California, USA
 http://www.fws.gov/redbluff/rbdd_jsmp.aspx




 - Original Message 

 From: Gene Leynesgleyne...@gmail.com gleynes%...@gmail.com
 To: r-help@r-project.org
 Sent: Tue, January 25, 2011 9:28:20 AM
 Subject: [R] ggplot - controlling point size

 Can anyone illuminate the following for me?
 How can I get rid of the blue line in the key in the second plot?

 ## Create a simple data frame
 df=data.frame(x=1:1000, y=2*1:1000+rnorm(1000,sd=1000),
 type=sample(letters[1:2],1000, replace=TRUE))

 ## Very nice!  Almost what I want
 qplot(x, y, data=df, colour=factor(type)) + geom_smooth()

 ## Make a nicer plot, with smaller points
 ## but why does that add the little blue line with a 1?
 qplot(x, y, data=df, colour=factor(type), size=1) + geom_smooth()


 --
 Brian S. Diggs, PhD
 Senior Research Associate, Department of Surgery
 Oregon Health  Science University


[[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] Extracting SSE from lm

2011-01-25 Thread Greg Snow
It is not clear what you are doing or why you are doing it.  If you tell us 
your ultimate goal we may be able to help you find a way that does not require 
all the computing that you are doing.

How do you get your coefficients? Are you using lm? Have you looked at the 
resid function?

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Brian J Mingus
 Sent: Tuesday, January 25, 2011 9:08 AM
 To: R-help@r-project.org
 Subject: [R] Extracting SSE from lm
 
 Apologies for this simple question -
 
 Given the number of comparisons I need to do it has become somewhat
 laborious to compute the SSE manually. I first have to extract the
 coefficients, build the model and run the model on the data. So far I
 haven't found any method in R that will do this for me. Is there a
 method
 that I haven't seen, or is there a small function I could write that
 would
 do this, and how might I go about that?
 
 Thanks,
 
 Brian
 
   [[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] Extracting SSE from lm

2011-01-25 Thread Peter Ehlers

On 2011-01-25 08:08, Brian J Mingus wrote:

Apologies for this simple question -

Given the number of comparisons I need to do it has become somewhat
laborious to compute the SSE manually. I first have to extract the
coefficients, build the model and run the model on the data. So far I
haven't found any method in R that will do this for me. Is there a method
that I haven't seen, or is there a small function I could write that would
do this, and how might I go about that?


You can always write a function to automate whatever
you're doing now. But if I understand what you need,
try:

 tail( anova( yourModel )[, 2], 1)

Peter Ehlers



Thanks,

Brian

[[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] Warning with predict.glm method

2011-01-25 Thread Lars Bishop
Dear list,

When I use the predict.glm method on a glm fitted object, I get the
following warning message:

In addition: Warning message:
 In predict.lm(object, x) :
  prediction from a rank-deficient fit may be misleading

As the documentation says this happens if the fit is rank-deficient, some
of the columns of the design matrix will have been dropped.

It is my understanding that this means that at least one predictor variable
in the design matrix can be replicated by a linear combination of the other
predictors. But this doesn't seem the case in my data set. I noticed that
the problem goes away after removing higher order interaction terms from the
model. Some of the coefficients from those terms were NA as shown in the
summary(glm).

I'm wondering if my interpretation of the message is correct, and/or in what
type of situations would I get this warning message.

Thanks in advance for your help.

Lars.

[[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] Counting number of rows with two criteria in dataframe

2011-01-25 Thread Ryan Utz
Hi R-users,

I'm trying to find an elegant way to count the number of rows in a dataframe
with a unique combination of 2 values in the dataframe. My data is
specifically one column with a year, one with a month, and one with a day.
I'm trying to count the number of days in each year/month combination. But
for simplicity's sake, the following dataset will do:

x-c(1,1,1,1,2,2,2,2,3,3,3,3)
y-c(1,1,2,2,3,3,4,4,5,5,6,6)
z-c(1,2,3,4,5,6,7,8,9,10,11,12)
X-data.frame(x y z)

So with dataset X, how would I count the number of z values (3rd column in
X) with unique combinations of the first two columns (x and y)? (for
instance, in the above example, there are 2 instances per unique combination
of the first two columns). I can do this in Matlab and it's easy, but since
I'm new to R this is royally stumping me.

Thanks,
Ryan

-- 
Ryan Utz
Postdoctoral research scholar
University of California, Santa Barbara
(724) 272 7769

[[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] Counting number of rows with two criteria in dataframe

2011-01-25 Thread Henrique Dallazuanna
If you want count:

xtabs( ~ x + y, X)


or sum:

 xtabs(z ~ x + y, X)


On Tue, Jan 25, 2011 at 5:25 PM, Ryan Utz utz.r...@gmail.com wrote:

 Hi R-users,

 I'm trying to find an elegant way to count the number of rows in a
 dataframe
 with a unique combination of 2 values in the dataframe. My data is
 specifically one column with a year, one with a month, and one with a day.
 I'm trying to count the number of days in each year/month combination. But
 for simplicity's sake, the following dataset will do:

 x-c(1,1,1,1,2,2,2,2,3,3,3,3)
 y-c(1,1,2,2,3,3,4,4,5,5,6,6)
 z-c(1,2,3,4,5,6,7,8,9,10,11,12)
 X-data.frame(x y z)

 So with dataset X, how would I count the number of z values (3rd column in
 X) with unique combinations of the first two columns (x and y)? (for
 instance, in the above example, there are 2 instances per unique
 combination
 of the first two columns). I can do this in Matlab and it's easy, but since
 I'm new to R this is royally stumping me.

 Thanks,
 Ryan

 --
 Ryan Utz
 Postdoctoral research scholar
 University of California, Santa Barbara
 (724) 272 7769

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] subsetting based on joint values of critera

2011-01-25 Thread Simon Kiss
Dear colleagues, I have a dataset that looks as below.

I would like to make a new dataset that excludes the cases which are joint 
conjunctions of particular state names and years, so Connecticut and 2010, 
Maryland and 2010 and Vermont and 2010.

I'm trying the following subset code: 
newdata- subset(bpa, (!State==Connecticut  year2010))

It appears that it's only evaluating both criteria independently and not 
jointly, so this is returning all cases in 2008 and 2009, leaving out 
connecticut for those years as well.
How do I get subset to return a dataset based on the joint occurrence of values 
of two variables?

Yours,  Simon Kiss

str(bpa)
'data.frame':   150 obs. of  5 variables:
 $ State   : Factor w/ 50 levels Alabama,Alaska,..: 1 2 3 4 5 6 7 8 9 10 ...
 $ year: num  2008 2008 2008 2008 2008 ...
 $ ban : num  0 0 0 0 0 0 0 0 0 0 ...
 $ partisan: Factor w/ 3 levels democrat,mixed,..: 1 1 1 1 1 1 1 2 3 2 ...
 $ news: num  1.67 2 0 0 2.38 ...
*
Simon J. Kiss, PhD
Assistant Professor, Wilfrid Laurier University
73 George Street
Brantford, Ontario, Canada
N3T 2C9
Cell: +1 519 761 7606

__
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] Importing xls from a http://

2011-01-25 Thread cameron

I know a lot of people asked similar questions like this.  I have tried using 

read.xls ()
Error in .Call(ReadXls, file, colNames, sheet, type, from, rowNames,  : 
  Incorrect number of arguments (11), expecting 10 for ReadXls

read.table or read.csv (Wrong table format)

odbcConnectExcel have problem with the URL 

I want to import this excel file
(http://www.econ.yale.edu/~shiller/data/ie_data.xls) from row 8 in Data
sheet.

Thanks
Cameron
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Importing-xls-from-a-http-tp3236800p3236800.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 Derivate for Nonlinear Growth Models

2011-01-25 Thread acocac

Hi!! Im doing my graduated work in Onion Curves Growth with Nonlinear Models,
I'm amateur in R so i have  doubt how i put or program next models,

http://r.789695.n4.nabble.com/file/n3236748/96629508.png 

Also, i cant derivate for Gauss Model, and Richard Model dont have funtion,
If someone could help me, i was so grate,


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-Derivate-for-Nonlinear-Growth-Models-tp3236748p3236748.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] Does anybody knows the default value of starting value in glm?

2011-01-25 Thread Akram Khaleghei Ghosheh balagh
Hello ;

Do you know what is the default value of starting value in glm ? glm(...,
start=c(),... )
I know that it is NULL by default but it need a value to start iteration .
what is this value?

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.


[R] Help with calculating correlation coefficient - creating a network

2011-01-25 Thread kparamas

Hi,

I am creating a correlation based graph for the data 27 X 3040.

I am not sure if I am allocating enough space for the data.
I am using the following .R file (which is an example for geneData)!
http://r.789695.n4.nabble.com/file/n3236801/sampleClimate.R
sampleClimate.R/nabble_a

and the data is in the file 
http://r.789695.n4.nabble.com/file/n3236801/data3y3w_landmask.txt
data3y3w_landmask.txt 

I am getting the following error in the line, 
 net - network(corm, directed = F)
Error in which.matrix.type(x) : subscript out of bounds

But if I use the geneData 500 X 26, it doesnt throw any error!
http://r.789695.n4.nabble.com/file/n3236801/geneData.txt geneData.txt 

Please help to fix the issue. 
(Note since I was having issue I took the transpose in the cor function.)

Thanks,
Kumaraguru
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-calculating-correlation-coefficient-creating-a-network-tp3236801p3236801.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] Counting number of rows with two criteria in dataframe

2011-01-25 Thread Ista Zahn
Hi Ryan,
One option would be

X$a - paste(X$x, X$y, sep=.)
table(X$a)

Best,
Ista

On Tue, Jan 25, 2011 at 2:25 PM, Ryan Utz utz.r...@gmail.com wrote:
 Hi R-users,

 I'm trying to find an elegant way to count the number of rows in a dataframe
 with a unique combination of 2 values in the dataframe. My data is
 specifically one column with a year, one with a month, and one with a day.
 I'm trying to count the number of days in each year/month combination. But
 for simplicity's sake, the following dataset will do:

 x-c(1,1,1,1,2,2,2,2,3,3,3,3)
 y-c(1,1,2,2,3,3,4,4,5,5,6,6)
 z-c(1,2,3,4,5,6,7,8,9,10,11,12)
 X-data.frame(x y z)

 So with dataset X, how would I count the number of z values (3rd column in
 X) with unique combinations of the first two columns (x and y)? (for
 instance, in the above example, there are 2 instances per unique combination
 of the first two columns). I can do this in Matlab and it's easy, but since
 I'm new to R this is royally stumping me.

 Thanks,
 Ryan

 --
 Ryan Utz
 Postdoctoral research scholar
 University of California, Santa Barbara
 (724) 272 7769

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] Importing xls from a http://

2011-01-25 Thread Gabor Grothendieck
On Tue, Jan 25, 2011 at 2:06 PM, cameron raymond...@invesco.com wrote:

 I know a lot of people asked similar questions like this.  I have tried using

 read.xls ()
 Error in .Call(ReadXls, file, colNames, sheet, type, from, rowNames,  :
  Incorrect number of arguments (11), expecting 10 for ReadXls

 read.table or read.csv (Wrong table format)

 odbcConnectExcel have problem with the URL

 I want to import this excel file
 (http://www.econ.yale.edu/~shiller/data/ie_data.xls) from row 8 in Data
 sheet.

How to import a spreadsheet from the internet was asked less than 24
hours ago on this list.  See:
http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows

e.g.

library(gdata)
URL - http://www.econ.yale.edu/~shiller/data/ie_data.xls;
DF - read.xls(URL, pattern = Fraction)


-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Predictions with 'missing' variables

2011-01-25 Thread Axel Urbiz
Dear List,

I think I'm going crazy here...can anyone explain why do I get the same
predictions in train and test data sets below when the second has a missing
input?

y - rnorm(1000)
x1 - rnorm(1000)
x2 - rnorm(1000)
train - data.frame(y,x1,x2)
test - data.frame(x1)

myfit - glm(y ~ x1 + x2, data=train)
summary(myfit)
all(predict(myfit, test) == predict(myfit, train))

[1] TRUE



Thanks,

Axel.

[[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] subsetting based on joint values of critera

2011-01-25 Thread Ista Zahn
Hi Simon,
You almost had it! Just need to move the negation outside the rest of
the logic, and remove the quotes from year. Not actually tested (no
data), but I think

newdata- subset(bpa, !(State==Connecticut  year2010))

should do it.

Best,
Ista

On Tue, Jan 25, 2011 at 1:34 PM, Simon Kiss simonjk...@yahoo.ca wrote:
 Dear colleagues, I have a dataset that looks as below.

 I would like to make a new dataset that excludes the cases which are joint 
 conjunctions of particular state names and years, so Connecticut and 2010, 
 Maryland and 2010 and Vermont and 2010.

 I'm trying the following subset code:
 newdata- subset(bpa, (!State==Connecticut  year2010))

 It appears that it's only evaluating both criteria independently and not 
 jointly, so this is returning all cases in 2008 and 2009, leaving out 
 connecticut for those years as well.
 How do I get subset to return a dataset based on the joint occurrence of 
 values of two variables?

 Yours,  Simon Kiss

 str(bpa)
 'data.frame':   150 obs. of  5 variables:
  $ State   : Factor w/ 50 levels Alabama,Alaska,..: 1 2 3 4 5 6 7 8 9 10 
 ...
  $ year    : num  2008 2008 2008 2008 2008 ...
  $ ban     : num  0 0 0 0 0 0 0 0 0 0 ...
  $ partisan: Factor w/ 3 levels democrat,mixed,..: 1 1 1 1 1 1 1 2 3 2 ...
  $ news    : num  1.67 2 0 0 2.38 ...
 *
 Simon J. Kiss, PhD
 Assistant Professor, Wilfrid Laurier University
 73 George Street
 Brantford, Ontario, Canada
 N3T 2C9
 Cell: +1 519 761 7606

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] Predictions with 'missing' variables

2011-01-25 Thread Ista Zahn
See the note in the help page for ?predict.glm

Best,
Ista

On Tue, Jan 25, 2011 at 2:59 PM, Axel Urbiz axel.ur...@gmail.com wrote:
 Dear List,

 I think I'm going crazy here...can anyone explain why do I get the same
 predictions in train and test data sets below when the second has a missing
 input?

 y - rnorm(1000)
 x1 - rnorm(1000)
 x2 - rnorm(1000)
 train - data.frame(y,x1,x2)
 test - data.frame(x1)

 myfit - glm(y ~ x1 + x2, data=train)
 summary(myfit)
 all(predict(myfit, test) == predict(myfit, train))

 [1] TRUE



 Thanks,

 Axel.

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.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] Manual two-stage least squares in R

2011-01-25 Thread Katharina Ley
Hi,

I am trying to manipulate a gls regression model output to adjust for use of
two-stage least squares. Basically, I want to estimate a model, then feed in
a new set of residuals, then re-calculate all of the model output (i.e. the
standard errors of the estimators, etc.). I have found some documentation on
doing this in stata, which is below:
http://www.stata.com/help.cgi?ereturn

I am wondering whether there is a function like this ereturn() (see
http://www.stata.com/help.cgi?ereturn) in R, and whether this might allow me
to achieve something similar.

Thanks so much!

[[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] lattice draw.key(): position of key in panels

2011-01-25 Thread Boris.Vasiliev
Good afternoon,

I am working on a plot that requires custom legends to be placed in some
panels of the plot; other panels do not contain legends.  The problem
that I run into is positioning of the legend in individual panels. In
particular, the 'x' and 'y' elements of the key-list are ignored by
draw.key() when it is called from inside a panel function.  As a result,
the legend is placed in the middle of the panel.  The example below
illustrates this problem.

df - data.frame(x=c(1,1),y=c(1,2),type=c(A,B))

panel.xyplot.x - function(...) {
  # draw data
  panel.xyplot(...)

  # create key-list
  pnlid - panel.number()
  lbl - ifelse(pnlid==1,AA,BB)
  pts - Rows(trellis.par.get(superpose.symbol),pnlid)
  key - list(points=pts,text=list(lbl),x=0.1,y=0.9,corner=c(0,1))

  # draw key
  draw.key(key,draw=TRUE)
}

oltc - xyplot(y~x|type,data=df,panel=panel.xyplot.x)
print(oltc)

I tried using 'vp=current.viewport()' in the call to draw.key() but it
did not help.  Can anybody suggest the proper way to specify position of
the key-list so that it is respected by draw.key() when called within a
panel function?

Sincerely,
Boris Vasiliev.

__
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] Manual two-stage least squares in R

2011-01-25 Thread Kevin Wright
Your question has some similarities this paper: Alison Smith, Brian
Cullis, and Arthur Gilmour. The analysis of crop variety evaluation
data in Australia. Aust. N. Z. J. Stat., 43:129--145, 2001.

In that paper, the authors fit a mixed model with several random
effects.  The variances are then held fixed while one of the model
terms is changed from a random effect to a fixed effect and the model
is re-fit using the constrained variances.  They refer to this as
unshrinking the BLUPs.  This is accomplished with ASREML or the R
version asreml-r, a commercial package (does have a 30-day free
trial).

Not sure if this would help you at all.

Good luck,

Kevin Wright


On Tue, Jan 25, 2011 at 2:47 PM, Katharina Ley kat...@umich.edu wrote:
 Hi,

 I am trying to manipulate a gls regression model output to adjust for use of
 two-stage least squares. Basically, I want to estimate a model, then feed in
 a new set of residuals, then re-calculate all of the model output (i.e. the
 standard errors of the estimators, etc.). I have found some documentation on
 doing this in stata, which is below:
 http://www.stata.com/help.cgi?ereturn

 I am wondering whether there is a function like this ereturn() (see
 http://www.stata.com/help.cgi?ereturn) in R, and whether this might allow me
 to achieve something similar.

 Thanks so much!

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




-- 
Kevin Wright

__
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] MAtrix addressing

2011-01-25 Thread Alaios
Hello
I would like to ask you if it is possible In R Cran to change the default way 
of addressing a matrix.
for example
matrix(data=seq(from=1,to=4,nrow=2,ncol=2, by row numbering) # not having R at 
this pc

will create something like the following
1 2
3 4

the way R address this matrix is from top left corner moving to bottom right.
The cell numbers in that way are 
1 2
3 4

IS it possible to change this default addresing number to something that goes 
bottom left to top right? In this simple case I want to have
3 4
1 2

Would that be possible?

I would like to thank y for your help
Regards
Alex

__
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] FW: question about the pt() calculation

2011-01-25 Thread Leitch, Matthew C.


From: Leitch, Matthew C.
Sent: Monday, January 24, 2011 6:53 PM
To: 'i...@network-theory.co.uk'
Subject: question about the pt() calculation

Hello

Thank you for your time. I am a graduate student at the University of Texas 
Medical Branch, and I was wondering if you could help me with a R program I am 
writing. I have some data that is stored a file that has 1733 rows and 4 
columns. Each row is independent, so I have a loop system so I don't have to 
manually perform 1733 t-tests. However I got most of it to work, thanks to the 
An Introduction to R book and a helpful colleague. But I am having some 
difficulty with getting my t-test scores converted to p-values. The pt() test 
won't take the t object, but I am unsure how to make it create a p-value for 
each row. If you have any suggestions they would be greatly appreciated.

Best Wishes
Matt
cancer-read.table(group2.txt, header=TRUE)
noncancer-read.table(group1.txt, header=TRUE)

#meanc-mean(cancer)
#meannc-mean(noncancer)
#varc-var(cancer)
#varnc-var(noncancer)
#Sx1x2-sqrt((varc+varnc)/2)
#n-4
#t-(noncancer-cancer)/(Sx1x2*(sqrt(2/n)))
#df-(2*n)-2
#pt(t,df)*2


answer = matrix(,1733,1);
alpha = 0.05;


#for(i=1:1733)
#{
#  meanc = mean(cancer[i,]);
#  meannc = mean(noncancer[i,]);
#  
#  varc = var(cancer[i,]);
#  varnc = var(noncancer[i,]); 
#
#  Sx1x2 = sqrt((varc+varnc)/2);
#  n = 4;
#  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
#  df = 2*n - 2;
#
#
#  answer[i,1] = pt(t,df)*2;
#
#  if (answer[i,1] = alpha)
#  {
#sing.
#  }
#  else
#  {
#nonsing.
#  }
#}

for(i in 1:1733)
{
  meanc = mean(cancer[i,]);
  meannc = mean(noncancer[i,]);
  
  varc = var(cancer[i,]);
  varnc = var(noncancer[i,]); 

  Sx1x2 = sqrt((varc+varnc)/2);
  n = 4;
  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
  df = 2*n - 2;

  answer[i,1] = pt(t,df)*2 ;

  if (answer[i,1]  alpha)
  {
banswer[i,1] = 1;
  }
  else
  {
banswer[i,1] = 0;
  }

  #ifelse(answer[i,1]  alpha, banswer[i,1] = 1, banswer[i,1] = 0);



}__
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] 3D Binning

2011-01-25 Thread Petr Savicky
On Tue, Jan 25, 2011 at 06:00:36AM -0800, vioravis wrote:
 
 I am trying to do binning on three variables (3d binning). The bin boundaries
 are specified by the user separately for each variable. I used the bin2
 function in the 'ash' package for 2d binning that involves only two
 variables but didn't any package for similar binning with three variables.
 Are there any packages or codes available for 3d binning?? Thank you. 

Try the following, possibly with different breaks for each dimension.

  x - matrix(rnorm(3), ncol=3)
  breaks - seq(-1, 1, length=5)
  xints - data.frame(
  x1=cut(x[, 1], breaks=breaks),
  x2=cut(x[, 2], breaks=breaks),
  x3=cut(x[, 3], breaks=breaks))
  table(complete.cases(xints))
  xtabs(~ ., xints)

Hope this helps.

Petr Savicky.

__
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] function application

2011-01-25 Thread Roy Shimizu
Suppose I have a function, like list, that takes a variable number of
arguments, and I have those arguments in some vector x.  How can execute the
function with the *contents* of x as its arguments?  I.e., I don't want
list(x), but rather list(x[[1]], x[[2]], ..., x[[n]]), but I don't want to
spell out the individual elements of x (either because I want to do this
programmatically, so I cannot code an expression like
list(x[[1]],...,x[[n]]) because the value of n is not know until run time,
or else, simply to avoid the tedium of typing out all the elements of x
individually).

Thanks!

Roy

P.S. In Python, if x is some sequence-like object (e.g. a list or a tuple),
and f is some function, the expression f(*x) causes f to be called with the
*contents* of x as its arguments.  (This is to be distinguished from f(x),
which calls f with x as its sole argument.)  In Mathematica, one can achieve
a similar effect using the Apply function: Apply[f, x].  I'm looking for the
equivalent of this in R.

[[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] FW: question about the pt() calculation

2011-01-25 Thread Leitch, Matthew C.


From: Leitch, Matthew C.
Sent: Monday, January 24, 2011 6:53 PM
To: 'i...@network-theory.co.uk'
Subject: question about the pt() calculation

Hello

Thank you for your time. I am a graduate student at the University of Texas 
Medical Branch, and I was wondering if you could help me with a R program I am 
writing. I have some data that is stored a file that has 1733 rows and 4 
columns. Each row is independent, so I have a loop system so I don't have to 
manually perform 1733 t-tests. However I got most of it to work, thanks to the 
An Introduction to R book and a helpful colleague. But I am having some 
difficulty with getting my t-test scores converted to p-values. The pt() test 
won't take the t object, but I am unsure how to make it create a p-value for 
each row. If you have any suggestions they would be greatly appreciated.

Best Wishes
Matt
cancer-read.table(group2.txt, header=TRUE)
noncancer-read.table(group1.txt, header=TRUE)

#meanc-mean(cancer)
#meannc-mean(noncancer)
#varc-var(cancer)
#varnc-var(noncancer)
#Sx1x2-sqrt((varc+varnc)/2)
#n-4
#t-(noncancer-cancer)/(Sx1x2*(sqrt(2/n)))
#df-(2*n)-2
#pt(t,df)*2


answer = matrix(,1733,1);
alpha = 0.05;


#for(i=1:1733)
#{
#  meanc = mean(cancer[i,]);
#  meannc = mean(noncancer[i,]);
#  
#  varc = var(cancer[i,]);
#  varnc = var(noncancer[i,]); 
#
#  Sx1x2 = sqrt((varc+varnc)/2);
#  n = 4;
#  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
#  df = 2*n - 2;
#
#
#  answer[i,1] = pt(t,df)*2;
#
#  if (answer[i,1] = alpha)
#  {
#sing.
#  }
#  else
#  {
#nonsing.
#  }
#}

for(i in 1:1733)
{
  meanc = mean(cancer[i,]);
  meannc = mean(noncancer[i,]);
  
  varc = var(cancer[i,]);
  varnc = var(noncancer[i,]); 

  Sx1x2 = sqrt((varc+varnc)/2);
  n = 4;
  t = (noncancer-cancer)/(Sx1x2*(sqrt(2/n)));
  df = 2*n - 2;

  answer[i,1] = pt(t,df)*2 ;

  if (answer[i,1]  alpha)
  {
banswer[i,1] = 1;
  }
  else
  {
banswer[i,1] = 0;
  }

  #ifelse(answer[i,1]  alpha, banswer[i,1] = 1, banswer[i,1] = 0);



}__
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] function application

2011-01-25 Thread Erik Iverson

Suppose I have a function, like list, that takes a variable number of
arguments, and I have those arguments in some vector x.  How can execute the
function with the *contents* of x as its arguments?  I.e., I don't want
list(x), but rather list(x[[1]], x[[2]], ..., x[[n]]), but I don't want to
spell out the individual elements of x (either because I want to do this
programmatically, so I cannot code an expression like
list(x[[1]],...,x[[n]]) because the value of n is not know until run time,
or else, simply to avoid the tedium of typing out all the elements of x
individually).


In this particular case, because you want to create a list,

x - 1:10
as.list(x)

will do.


P.S. In Python, if x is some sequence-like object (e.g. a list or a tuple),
and f is some function, the expression f(*x) causes f to be called with the
*contents* of x as its arguments.  (This is to be distinguished from f(x),
which calls f with x as its sole argument.)  In Mathematica, one can achieve
a similar effect using the Apply function: Apply[f, x].  I'm looking for the
equivalent of this in R.


In general, if you already have a *list* and want to call a function
with the contents of that list as the arguments, then ?do.call is what
you need.

a - list(example, of, do.call)

#compare the two following expressions
paste(a)
do.call(paste, a)


--Erik

__
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] function application

2011-01-25 Thread Phil Spector

?do.call

Please provide a reproducible example if the help file is 
not sufficient.


- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Tue, 25 Jan 2011, Roy Shimizu wrote:


Suppose I have a function, like list, that takes a variable number of
arguments, and I have those arguments in some vector x.  How can execute the
function with the *contents* of x as its arguments?  I.e., I don't want
list(x), but rather list(x[[1]], x[[2]], ..., x[[n]]), but I don't want to
spell out the individual elements of x (either because I want to do this
programmatically, so I cannot code an expression like
list(x[[1]],...,x[[n]]) because the value of n is not know until run time,
or else, simply to avoid the tedium of typing out all the elements of x
individually).

Thanks!

Roy

P.S. In Python, if x is some sequence-like object (e.g. a list or a tuple),
and f is some function, the expression f(*x) causes f to be called with the
*contents* of x as its arguments.  (This is to be distinguished from f(x),
which calls f with x as its sole argument.)  In Mathematica, one can achieve
a similar effect using the Apply function: Apply[f, x].  I'm looking for the
equivalent of this in R.

[[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] Train error:: subscript out of bonds

2011-01-25 Thread mxkuhn
You should try different tuning parameters; the defaults are not likely to work 
for many datasets. I don't use the polynomial kernel too much but scale 
parameter values that are really of could cause this. Unlike the rbf, I don't 
know of any good techniques for estimating this.

Max

On Jan 25, 2011, at 11:47 AM, Neeti nikkiha...@gmail.com wrote:

 
 after using options(error=utils::recover) option, following is the output. if
 i am correct this means that in ksvm there is some problem, but really could
 not understand. could anyone please tell me what is wrong...
 
 any help will be great 
 
 thank you so much..
 
 
 Enter a frame number, or 0 to exit   
 
 1: train(train1, as.factor(trainset[, ncol(trainset)]), svmpoly,
 trControl = trainControl((method = cv), 10,
 2: train.default(train1, as.factor(trainset[, ncol(trainset)]), svmpoly,
 trControl = trainControl((method = c
 3: do.call(trControl$computeFunction, argList)
 4: function (X, FUN, ...) 
 5: FUN(X[[25]], ...)
 6: do.call(createModel, args)
 7: function (data, method, tuneValue, obsLevels, pp = NULL, ...) 
 8: ksvm(as.matrix(trainX), trainY, kernel = polydot(degree =
 tuneValue$.degree, scale = tuneValue$.scale, offset
 9: ksvm(as.matrix(trainX), trainY, kernel = polydot(degree =
 tuneValue$.degree, scale = tuneValue$.scale, offset
 10: .local(x, ...)
 11: ksvm(x[c(indexes[[i]], indexes[[j]]), , drop = FALSE][cind, ], yd[cind],
 type = type(ret), kernel = kernel, k
 12: ksvm(x[c(indexes[[i]], indexes[[j]]), , drop = FALSE][cind, ], yd[cind],
 type = type(ret), kernel = kernel, k
 13: .local(x, ...)
 
 -- 
 View this message in context: 
 http://r.789695.n4.nabble.com/Train-error-subscript-out-of-bonds-tp3234510p3236494.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.


Re: [R] FW: question about the pt() calculation

2011-01-25 Thread Phil Spector

Matthew -
   Others will probably tell you about the folly of performing
1733 t-tests on groups with 4 observations each, but an alternative
to your approach would be to use R to solve your problem.  (I'm
using var.equal=TRUE because that's what you're calculating, but
you might consider using the default behaviour assuming unequal
variances.)

onerow = function(i){
   thetest = t.test(noncancer[i,],cancer[i,],var.equal=TRUE)
   c(thetest$statistic,thetest$p.value,as.numeric(thetest$p.value  0.05))
}

answer = t(sapply(1:nrow(cancer),onerow))

Then answer should have the information that you want.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu

On Tue, 25 Jan 2011, Leitch, Matthew C. wrote:




From: Leitch, Matthew C.
Sent: Monday, January 24, 2011 6:53 PM
To: 'i...@network-theory.co.uk'
Subject: question about the pt() calculation

Hello

Thank you for your time. I am a graduate student at the University of Texas Medical 
Branch, and I was wondering if you could help me with a R program I am writing. I have 
some data that is stored a file that has 1733 rows and 4 columns. Each row is 
independent, so I have a loop system so I don't have to manually perform 1733 t-tests. 
However I got most of it to work, thanks to the An Introduction to R book and 
a helpful colleague. But I am having some difficulty with getting my t-test scores 
converted to p-values. The pt() test won't take the t object, but I am unsure how to make 
it create a p-value for each row. If you have any suggestions they would be greatly 
appreciated.

Best Wishes
Matt



__
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] ANOVA table look

2011-01-25 Thread Keith Jones


Y'all,

I need to get the look of a standard fixed effect ANOVA table:

anova(aov(meas~op*part,data=fs))
Analysis of Variance Table

Response: meas
  Df  Sum Sq Mean Sq F value Pr(F)
op 22.62   1.308  1.3193 0.2750
part  19 1185.43  62.391 62.9151 2e-16 ***
op:part   38   27.05   0.712  0.7178 0.8614
Residuals 60   59.50   0.992

when I perform a two-factor factorial with random factors analysis  
using:


fs.anova=lmer(meas~(1|op)+(1|part),data=fs)
 print(fs.anova)
Linear mixed model fit by REML
Formula: meas ~ (1 | op) + (1 | part)
   Data: fs
   AIC   BIC logLik deviance REMLdev
 417.6 428.7 -204.8410.7   409.6
Random effects:
 Groups   NameVariance   Std.Dev.
 part (Intercept) 1.0250e+01 3.2015e+00
 op   (Intercept) 1.8497e-16 1.3600e-08
 Residual 8.9167e-01 9.4428e-01
Number of obs: 120, groups: part, 20; op, 3

Fixed effects:
Estimate Std. Error t value
(Intercept)  22.3917 0.7211   31.05

The data is twenty parts, three operators with two replications of  
measurements on the twenty parts.


Any help would be appreciated.

Thanks,

Keith Jones

__
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] Does anybody knows the default value of starting value in glm?

2011-01-25 Thread Douglas Bates
On Tue, Jan 25, 2011 at 1:14 PM, Akram Khaleghei Ghosheh balagh
a.khaleg...@gmail.com wrote:
 Hello ;

 Do you know what is the default value of starting value in glm ? glm(...,
 start=c(),... )
 I know that it is NULL by default but it need a value to start iteration .
 what is this value?

Actually the typical call to glm ends up setting a value of mu and eta
from which the parameter values are calculated on the first iteration.
 See the initialize component for the particular family in which you
are interested to see how it creates mustart.

__
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] write.table -- maintain decimal places

2011-01-25 Thread Jim Moon
Hello, All,

How can I maintain the decimal places when using write.table()?

Jim

e.g.

df:
  EFFECT2  PVALUE
1 0.0230.88080
2 -0.260  0.08641
3 -0.114  0.45200

write.table(df,file='df.txt',quote=F,sep='\t',row.names=F)


df.txt:
EFFECT2PVALUE
0.023  0.8808
-0.26  0.08641
-0.114 0.452

[[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] post-hoc comparisons in GAMs (mgcv) with parametric terms

2011-01-25 Thread Julian Burgos
Dear list,

I´m wondering if there is something analogous to the TukeyHSD function
that could be used for parametric terms in a GAM.  I´m using the mgcv
package to fit models that have some continuous predictors (modeled as
smooth terms) and a single categorical predictor.  I would like to do
post hoc test on the categorical predictor in the models where it is
significant.
Any suggestions?

Thanks,

Julian

-- 
Julian Mariano Burgos
Hafrannsóknastofnunin/Marine Research Institute
Skúlagata 4, 121 Reykjavík, Iceland
Sími/Telephone : +354-5752037
Bréfsími/Telefax:  +354-5752001
Netfang/Email: jul...@hafro.is, jmbur...@uw.edu

__
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] write.table -- maintain decimal places

2011-01-25 Thread Sebastian P. Luque
On Tue, 25 Jan 2011 16:16:37 -0800,
Jim Moon moo...@ohsu.edu wrote:

 Hello, All, How can I maintain the decimal places when using
 write.table()?

Have a look at ?format.data.frame


-- 
Seb

__
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] crash when using hazard.ratio.plot from rms package

2011-01-25 Thread Hongying Li

Dear all,
I always encounter a crash when running hazard.ratio.plot from rms package with 
my predictor as a factor.
It works fine when the predictor is a continous score. 
Anyone encounters this too? Is this a bug or something?
Thanks,
Lilian
[[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] write.table -- maintain decimal places

2011-01-25 Thread Peter Ehlers

On 2011-01-25 16:16, Jim Moon wrote:

Hello, All,

How can I maintain the decimal places when using write.table()?

Jim

e.g.

df:
   EFFECT2  PVALUE
1 0.0230.88080
2 -0.260  0.08641
3 -0.114  0.45200

write.table(df,file='df.txt',quote=F,sep='\t',row.names=F)


 write.table(format(df, drop0trailing=FALSE), )

Peter Ehlers




df.txt:
EFFECT2PVALUE
0.023  0.8808
-0.26  0.08641
-0.114 0.452

[[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] write.table -- maintain decimal places

2011-01-25 Thread Jim Moon
Thank you for the response, Peter.  

The approach:
write.table(format(df, 
drop0trailing=FALSE),file='df.txt',quote=F,sep='\t',row.names=F)
surprisingly still results in some loss of trailing 0's.

df:
   EFFECT2  PVALUE
1 0.0230.88080
2 -0.260  0.08641
3 -0.114  0.45200

df.txt:
EFFECT2PVALUE
0.023  8.808e-01
-0.26  8.641e-02
-0.114 4.520e-01


-Original Message-
From: Peter Ehlers [mailto:ehl...@ucalgary.ca] 
Sent: Tuesday, January 25, 2011 5:09 PM
To: Jim Moon
Cc: r-help@r-project.org
Subject: Re: [R] write.table -- maintain decimal places

On 2011-01-25 16:16, Jim Moon wrote:
 Hello, All,

 How can I maintain the decimal places when using write.table()?

 Jim

 e.g.

 df:
EFFECT2  PVALUE
 1 0.0230.88080
 2 -0.260  0.08641
 3 -0.114  0.45200

 write.table(df,file='df.txt',quote=F,sep='\t',row.names=F)

  write.table(format(df, drop0trailing=FALSE), )

Peter Ehlers



 df.txt:
 EFFECT2PVALUE
 0.023  0.8808
 -0.26  0.08641
 -0.114 0.452

   [[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] write.table -- maintain decimal places

2011-01-25 Thread Peter Ehlers

On 2011-01-25 17:22, Jim Moon wrote:

Thank you for the response, Peter.

The approach:
write.table(format(df, 
drop0trailing=FALSE),file='df.txt',quote=F,sep='\t',row.names=F)
surprisingly still results in some loss of trailing 0's.



What version of R?
I'm using R version 2.12.1 Patched (2010-12-27 r53883)
and it works for me.

Peter Ehlers


df:
EFFECT2  PVALUE
1 0.0230.88080
2 -0.260  0.08641
3 -0.114  0.45200

df.txt:
EFFECT2PVALUE
0.023  8.808e-01
-0.26  8.641e-02
-0.114 4.520e-01


-Original Message-
From: Peter Ehlers [mailto:ehl...@ucalgary.ca]
Sent: Tuesday, January 25, 2011 5:09 PM
To: Jim Moon
Cc: r-help@r-project.org
Subject: Re: [R] write.table -- maintain decimal places

On 2011-01-25 16:16, Jim Moon wrote:

Hello, All,

How can I maintain the decimal places when using write.table()?

Jim

e.g.

df:
EFFECT2  PVALUE
1 0.0230.88080
2 -0.260  0.08641
3 -0.114  0.45200

write.table(df,file='df.txt',quote=F,sep='\t',row.names=F)


   write.table(format(df, drop0trailing=FALSE), )

Peter Ehlers




df.txt:
EFFECT2PVALUE
0.023  0.8808
-0.26  0.08641
-0.114 0.452

[[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] return object from loop inside a function

2011-01-25 Thread Nicolas Gutierrez

Hi All,

I have a for loop inside the function and I cannot get UUU to give me an 
updated grid.dens object when I run the function (it does update when I 
run just the for loop). Here's a simplified version of my function:


UUU=function(pop, grid.dens) {

for (i in 1:10){
Food=grid.dens[pop$yloc[i],pop$xloc[i]]   #use initial grid.dens values
Consumed=(pop$weight[i]*0.25)
Left=Food-Consumed
grid.dens[pop$yloc[i],pop$xloc[i]]=Left   #update grid.dens values on i
pop$birth[i]=pop$birth[i]+1
}
return(pop)
return(grid.dens)
}

I get an updated pop, but not an updated grid.dens.  What am I doing wrong?

Thanks!

Nico

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


  1   2   >