[R] Downloading tab separated data from internet

2011-12-03 Thread HC
Hi all,

I am trying to download some tab separated data from the internet. The data
is not available directly at the URL that could be known apriori. There is
an intermediate form where start and end dates have to be given to get to
the required page.

For example, I want to download data for a station 03015795. The form for
this station is at:

http://ida.water.usgs.gov/ida/available_records.cfm?sn=03015795

I could get the start date and end date from this form using:

# 
# Specifying station and reading from the opening form
stn-03015795
myurl-paste(http://ida.water.usgs.gov/ida/available_records.cfm?sn=,stn,sep=;)
mypage1 = readLines(myurl)

# Getting the start and end dates
mypattern = 'td align=center([^]*)/td'
datalines = grep(mypattern, mypage1[124], value=TRUE)
getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1)
gg = gregexpr(mypattern, datalines)
matches = mapply(getexpr,datalines,gg)
result = gsub(mypattern,'\\1',matches)
names(result)=NULL
mydates-result[1:2]

I want to know how I can feed these start and end dates to the form and
execute the button to go to the data page and then to download the data,
either as displayed in the browser or by saving as a file.

Any help on this is most appreciated.

Thanks.
HC







--
View this message in context: 
http://r.789695.n4.nabble.com/Downloading-tab-separated-data-from-internet-tp4152318p4152318.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] simple lm question

2011-12-03 Thread Worik R

 Sigh  Please note that your df and M are undoubtedly different
 objects by now:

 Right.  Not my most coherent day.

thanks
W



  M - matrix(runif(5*20), nrow=20)
  colnames(M) - c('a', 'b', 'c', 'd', 'e')
  l1 - lm(e~., data=as.data.frame(M))
  l1

 Call:
 lm(formula = e ~ ., data = as.data.frame(M))

 Coefficients:
 (Intercept)abcd
0.40139 -0.15032 -0.06242  0.13139  0.23905


  l3 - lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,**4])
  l3


 Call:
 lm(formula = M[, 5] ~ M[, 1] + M[, 2] + M[, 3] + M[, 4])

 Coefficients:
 (Intercept)   M[, 1]   M[, 2]   M[, 3]   M[, 4]
0.40139 -0.15032 -0.06242  0.13139  0.23905

 As expected.

 --
 David.


 On Sat, Dec 3, 2011 at 5:10 PM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

  In your code by supplying a vector M[,e] you are regressing e
 against all the variables provided in the data argument, including e
 itself -- this gives the very strange regression coefficients you
 observe. R has no way to know that that's somehow related to the e
 it sees in the data argument.


  In the suggested way,

 lm(formula = e ~ ., data = as.data.frame(M))

 e is regressed against everything that is not e and sensible results are
 given.


 But still 'l1 - lm(e~., data=df)' is not the same as 'l3 -
 lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,**4])'

  M - matrix(runif(5*20), nrow=20)
 colnames(M) - c('a', 'b', 'c', 'd', 'e')
 l1 - lm(e~., data=df)
 summary(l1)


 Call:
 lm(formula = e ~ ., data = df)

 Residuals:
Min   1Q   Median   3Q  Max
 -0.38343 -0.21367  0.03067  0.13757  0.49080

 Coefficients:
   Estimate Std. Error t value Pr(|t|)
 (Intercept)  0.285210.29477   0.9680.349
 a0.092830.30112   0.3080.762
 b0.239210.22425   1.0670.303
 c   -0.160270.24154  -0.6640.517
 d0.240250.20054   1.1980.250

 Residual standard error: 0.2871 on 15 degrees of freedom
 Multiple R-squared: 0.1602,Adjusted R-squared: -0.06375
 F-statistic: 0.7153 on 4 and 15 DF,  p-value: 0.5943

  l3 - lm(M[,5]~M[,1]+M[,2]+M[,3]+M[,**4])
 summary(l3)


 Call:
 lm(formula = M[, 5] ~ M[, 1] + M[, 2] + M[, 3] + M[, 4])

 Residuals:
Min   1Q   Median   3Q  Max
 -0.36355 -0.22679 -0.01202  0.18462  0.37377

 Coefficients:
   Estimate Std. Error t value Pr(|t|)
 (Intercept)  0.769720.24501   3.142  0.00672 **
 M[, 1]  -0.238300.24123  -0.988  0.33890
 M[, 2]  -0.020460.21958  -0.093  0.92699
 M[, 3]  -0.295180.22559  -1.308  0.21040
 M[, 4]  -0.315450.24570  -1.284  0.21866
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 0.2668 on 15 degrees of freedom
 Multiple R-squared: 0.2762,Adjusted R-squared: 0.08317
 F-statistic: 1.431 on 4 and 15 DF,  p-value: 0.272



[[alternative HTML version deleted]]

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


 David Winsemius, MD
 West Hartford, CT



[[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 installing Rtools

2011-12-03 Thread stillerfan
I'm a new user to R and recently installed R 2.14  for Windows 7 (64 bit).  I
have downloaded and ran Rtools 2.14 but do not see any new packages in the
install packages section of R.  I installed Rtools in a subdirectory to the
/library/ directory.  Does anyone have any idea what I could be doing wrong?

Thanks!

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-installing-Rtools-tp4152013p4152013.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 in removal of fixed pattern

2011-12-03 Thread arunkumar1111
Hi

I have column name as given below

If the variable is in log(X1 + 1) pattern it should be removed and i need
only X1

Input 
log(x1 + 1) 
x2
log(X3 +1)

Expected Output X1 X2 X3

Please help me


--
View this message in context: 
http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.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] Reading multiple text files and then combining into a dataframe

2011-12-03 Thread James Holland
I have a multiple text files, separated by a single space, that I need to
combine into a single data.frame.  Below is the track I'm on using
list.files to capture the names of the files and then lapply with
read.table.  But I run into problems making a usable dataframe out of the
data.


#Creating example data in similar format to data I have
sub - rep(1,10)
trial - seq(1,10,1)
size - rep(3,10)
shortest - rep(444,10)
startlab - rep(444,10)
endlab - rep(444,10)
startconf - rep(444,10)
endconf - rep(444,10)
steps - sample(1:30,10)
time - sample(1:300,10)

#creating example of text file and saving into a shared director with other
txt files

subject1 -
cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
write.table(subject1, C:Folder/R/subject1.txt, sep= )

#2nd example of same text file
sub - rep(2,10)
trial - seq(1,10,1)
size - rep(3,10)
shortest - rep(444,10)
startlab - rep(444,10)
endlab - rep(444,10)
startconf - rep(444,10)
endconf - rep(444,10)
steps - sample(1:30,10)
time - sample(1:300,10)

subject1 -
cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
write.table(subject1, C:Folder/R/subject2.txt, sep= )


setwd(C:Folder/R/)

#Getting list of file names
file_name - list.files(pattern=subject*)

mydata - lapply (file_name, read.table, sep= , header=T, row.names=NULL)



Thank you,
James

[[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] partial mantel tests in ecodist with intential NA values.

2011-12-03 Thread Nevil Amos
I would like to perform partial mantel tests  on only within group values, with 
between group values assigned to NA.
This is possible in package ncf partial.mantel.test, however this sues a 
different permutation to that used in ecodist.ecodist will not accept data with 
NA values, returning a matrix is not square error.

is it possible to perform this test in ecodist?

many thanks

Nevil Amos

 library(ecodist)
 library(ncf)
 x-sample(1:1000,20)
 y-sample(1:1000,20)
 z-sample(1:1000,20)
 M1-as.matrix( distance(x))
 M2 -as.matrix( distance(y ))
 M3-as.matrix( distance(z ))
 D1-(lower(M1))
 D2-(lower(M2))
 D3-(lower(M3))
 mantel(D1 ~ D2+D3, nperm=1000)
   mantelr  pval1  pval2  pval3  llim.2.5% ulim.97.5% 
0.09014696 0.1030 0.8980 0.1840 0.01857311 0.18468621 
 partial.mantel.test(M1,M2,M3,quiet=T)
$MantelR
r12 r13 r23   r12.3   r13.2 
 0.08977575  0.02170997 -0.01561346  0.09014696  0.02320821 

$p
[1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830

$call
[1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

attr(,class)
[1] partial.Mantel
 M1[1:10,11:20]-NA
 M1[11:20,1:10]-NA
 D1-(lower(M1))
 mantel(D1 ~ D2+D3, nperm=1000)
Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square.
 partial.mantel.test(M1,M2,M3,quiet=T)
$MantelR
 r12  r13  r23r12.3r13.2 
 0.054906562  0.003446670 -0.015613460  0.054967403  0.004310979 

$p
[1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764

$call
[1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

attr(,class)
[1] partial.Mantel
Warning message:
In partial.mantel.test(M1, M2, M3, quiet = T) :
  Missing values exist; Pairwise deletion will be used
__
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 tab separated data from internet

2011-12-03 Thread Prof Brian Ripley

AFAICS what you mean is 'how can I fill in an HTML form using R'.
Answer: use package RCurl.

Do study the posting guide: none of the 'at a minimum' information was 
given here.



On 03/12/2011 04:47, HC wrote:

Hi all,

I am trying to download some tab separated data from the internet. The data
is not available directly at the URL that could be known apriori. There is
an intermediate form where start and end dates have to be given to get to
the required page.

For example, I want to download data for a station 03015795. The form for
this station is at:

http://ida.water.usgs.gov/ida/available_records.cfm?sn=03015795

I could get the start date and end date from this form using:

#
# Specifying station and reading from the opening form
stn-03015795
myurl-paste(http://ida.water.usgs.gov/ida/available_records.cfm?sn=,stn,sep=;)
mypage1 = readLines(myurl)

# Getting the start and end dates
mypattern = 'td align=center([^]*)/td'
datalines = grep(mypattern, mypage1[124], value=TRUE)
getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1)
gg = gregexpr(mypattern, datalines)
matches = mapply(getexpr,datalines,gg)
result = gsub(mypattern,'\\1',matches)
names(result)=NULL
mydates-result[1:2]

I want to know how I can feed these start and end dates to the form and
execute the button to go to the data page and then to download the data,
either as displayed in the browser or by saving as a file.

Any help on this is most appreciated.

Thanks.
HC



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


Re: [R] Help! Big problem when using browser() to do R debugging?

2011-12-03 Thread Liviu Andronic
On Sat, Dec 3, 2011 at 2:38 AM, Michael comtech@gmail.com wrote:
 Hi all,

 Could you please help me?

 I am having the following weird problem when debugging R programs
 using browser():

 In my function, I've inserted a browser() in front of Step 1. My
 function has 3 steps and at the end of each step, it will print out
 the message Step i is done...

 However, after I hit ENTER when the program stopped before Step 1
 and entered into the debugging mode, it not only executed the next
 line(i.e. the Step 1), but also all the (many) remaining lines in that
 function, as shown below:


 Browse[1]
 [1] Step 1 is done..
 [1] Step 2 is done..
 [1] Step 3 is done..

 Then it automatically quited the debugging mode and when I tried to
 check the value of myobj, I've got the following error message:

 names(myobj)
 Error: object 'myobj' not found
 No suitable frames for recover()

 

 So my question is: why did one key stroke ENTER lead it to execute
 all the remaining lines in that function and then returned from the
 function and quited the debugging mode?

As soon as you get into 'debug' mode, type 'n', hit enter, then you
can simply hit enter to evaluate the fun step by step. To exit the
step-by-step, type 'c' and hit enter: this will evaluate the rest of
the function.

Regards
Liviu


 Thanks a lot!

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



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

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


Re: [R] Problem installing Rtools

2011-12-03 Thread Duncan Murdoch

On 11-12-02 10:25 PM, stillerfan wrote:

I'm a new user to R and recently installed R 2.14  for Windows 7 (64 bit).  I
have downloaded and ran Rtools 2.14 but do not see any new packages in the
install packages section of R.  I installed Rtools in a subdirectory to the
/library/ directory.  Does anyone have any idea what I could be doing wrong?



Rtools doesn't contain R packages, it contains various compilers and 
tools that you could use to build R and R packages.  So you should 
install it in its own directory.  I usually use c:/Rtools.


Duncan Murdoch

__
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] Project local libraries (reproducible research)

2011-12-03 Thread Jim Lemon

On 12/03/2011 06:04 AM, Hadley Wickham wrote:

Hi all,

I was wondering if any one had scripts that they could share for
capturing the current version of R packages used for a project. I'm
interested in creating a project local library so that you're safe if
someone (e.g. the ggplot2 author) updates a package you're relying on
and breaks your code.   I could fairly easily hack together, but I was
wondering if any one had any neat scripts they'd care to share.


Hi Hadley,
This makes quite a few assumptions, but I would build a list of packages 
called in R scripts:


# get all calls to library or require in a subdirectory of scripts
packagestrings-c(system(grep library *.R,intern=TRUE),
 system(grep require *.R,intern=TRUE))
# get the unique package names
packagenames-unique(sapply(strsplit(packagestrings,[()]),[,2))
# get the information on all installed packages in the system
installedpackages-installed.packages()
# get the indices of the packages used in the subdirectory
whichpackages-which(match(rownames(installedpackages),packagenames,0)0)
# get the version information for each used package
installedpackages[whichpackages,Built]

Jim

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


[R] Data alignment

2011-12-03 Thread syrvn
Hello!

I have a data.frame which looks like:

Name - Value
A - 400
A - 300
B - 200
B - 350
C - 500
C - 350
D - 450 
D - 600
E - 700 
E - 750
F - 630
F - 650

I want to add another column where all A,B should get an index 1, all C,D an
index of 2 and all E,F an index of 3 so that the data.frame looks like:

ID - Name - Value
1 - A - 400
1 - A - 300
1 - B - 200
1 - B - 350
2 - C - 500
2 - C - 350
2 - D - 450 
2 - D - 600
3 - E - 700 
3 - E - 750
3 - F - 630
3 - F - 650

My data.frame is quite big so I cannot add all values by hand.


Cheers




--
View this message in context: 
http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153024.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] side-by-side map with different geographies using spplot

2011-12-03 Thread Roger Bivand
David Epstein davideps at umich.edu writes:

 
 Hello,
 
 I want to create side-by-side maps of similar attribute data in two 
 different cities using a single legend.
 
 To simply display side-by-side census block group boundary 
 (non-thematic) maps for Minneapolis  Cleveland I do the following:
 

 
 I can display a single thematic map for a city using spplot as follows:
 
 spplot(Minneapolis,Thematic_Data_Column)
 

The spplot function uses lattice graphics, so you may use the standard methods
for the trellis objects that it returns. If you did something like:

sp_out_Minneapolis - spplot(Minneapolis, your_var)
print(sp_out_Minneapolis, split=c(1, 1, 2, 1), more=TRUE)
sp_out_Cleveland - spplot(Cleveland, your_var)
print(sp_out_,Cleveland split=c(2, 1, 2, 1), more=FALSE)

you will get some of the way there. If in addition you would like only one
legend using the same breaks and colours, you'll need to use appropriate
arguments to spplot() in both calls to handle this.

It may be worth considering posting queries of this kind on R-sig-geo, as
response may be forthcoming more quickly there.

Hope this helps,

Roger

 
 thank you,
 -david
 


__
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] partial mantel tests in ecodist with intential NA values.

2011-12-03 Thread Sarah Goslee
It is not possible in ecodist, and I'd be wary of doing it in other
packages. Instead, I would consider the model matrix approach described in
Legendre and Fortin 1989.

Sarah

On Saturday, December 3, 2011, Nevil Amos nevil.a...@gmail.com wrote:
 I would like to perform partial mantel tests  on only within group
values, with between group values assigned to NA.
 This is possible in package ncf partial.mantel.test, however this sues a
different permutation to that used in ecodist.ecodist will not accept data
with NA values, returning a matrix is not square error.

 is it possible to perform this test in ecodist?

 many thanks

 Nevil Amos

 library(ecodist)
 library(ncf)
 x-sample(1:1000,20)
 y-sample(1:1000,20)
 z-sample(1:1000,20)
 M1-as.matrix( distance(x))
 M2 -as.matrix( distance(y ))
 M3-as.matrix( distance(z ))
 D1-(lower(M1))
 D2-(lower(M2))
 D3-(lower(M3))
 mantel(D1 ~ D2+D3, nperm=1000)
   mantelr  pval1  pval2  pval3  llim.2.5% ulim.97.5%
 0.09014696 0.1030 0.8980 0.1840 0.01857311 0.18468621
 partial.mantel.test(M1,M2,M3,quiet=T)
 $MantelR
r12 r13 r23   r12.3   r13.2
  0.08977575  0.02170997 -0.01561346  0.09014696  0.02320821

 $p
 [1] 0.09590410 0.30769231 0.47552448 0.09490509 0.30169830

 $call
 [1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

 attr(,class)
 [1] partial.Mantel
 M1[1:10,11:20]-NA
 M1[11:20,1:10]-NA
 D1-(lower(M1))
 mantel(D1 ~ D2+D3, nperm=1000)
 Error in mantel(D1 ~ D2 + D3, nperm = 1000) : Matrix not square.
 partial.mantel.test(M1,M2,M3,quiet=T)
 $MantelR
 r12  r13  r23r12.3r13.2
  0.054906562  0.003446670 -0.015613460  0.054967403  0.004310979

 $p
 [1] 0.2837163 0.4275724 0.4555445 0.2857143 0.4235764

 $call
 [1] partial.mantel.test(M1 = M1, M2 = M2, M3 = M3, quiet = T)

 attr(,class)
 [1] partial.Mantel
 Warning message:
 In partial.mantel.test(M1, M2, M3, quiet = T) :
  Missing values exist; Pairwise deletion will be used
 __
 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.


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[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] Data alignment

2011-12-03 Thread Sarah Goslee
I doubt your data frame looks like that, with all the -, but regardless you
can use ifelse() to construct your column.

Sarah

On Saturday, December 3, 2011, syrvn ment...@gmx.net wrote:
 Hello!

 I have a data.frame which looks like:

 Name - Value
 A - 400
 A - 300
 B - 200
 B - 350
 C - 500
 C - 350
 D - 450
 D - 600
 E - 700
 E - 750
 F - 630
 F - 650

 I want to add another column where all A,B should get an index 1, all C,D
an
 index of 2 and all E,F an index of 3 so that the data.frame looks like:

 ID - Name - Value
 1 - A - 400
 1 - A - 300
 1 - B - 200
 1 - B - 350
 2 - C - 500
 2 - C - 350
 2 - D - 450
 2 - D - 600
 3 - E - 700
 3 - E - 750
 3 - F - 630
 3 - F - 650

 My data.frame is quite big so I cannot add all values by hand.


 Cheers




 --
 View this message in context:
http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153024.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.


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[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] help in removal of fixed pattern

2011-12-03 Thread Sarah Goslee
You can use gsub() to replace parts of strings.

Sarah

On Saturday, December 3, 2011, arunkumar akpbond...@gmail.com wrote:
 Hi

 I have column name as given below

 If the variable is in log(X1 + 1) pattern it should be removed and i need
 only X1

 Input
 log(x1 + 1)
 x2
 log(X3 +1)

 Expected Output X1 X2 X3

 Please help me


 --
 View this message in context:
http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.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.


-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

[[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] Data alignment

2011-12-03 Thread jim holtman
try this:

 match(x$Name x - read.table(text = Name - Value
+ A - 400
+ A - 300
+ B - 200
+ B - 350
+ C - 500
+ C - 350
+ D - 450
+ D - 600
+ E - 700
+ E - 750
+ F - 630
+ F - 650, header = TRUE, as.is = TRUE)
 map - data.frame(key =   c(A, B, C, D, E, F)
+ , value = c( 1,   1,   2,   2,   3,   3)
+ , stringsAsFactors = FALSE
+ )
 x$ID - map$value[match(x$Name, map$key)]
 x
   Name X. Value ID
1 A  -   400  1
2 A  -   300  1
3 B  -   200  1
4 B  -   350  1
5 C  -   500  2
6 C  -   350  2
7 D  -   450  2
8 D  -   600  2
9 E  -   700  3
10E  -   750  3
11F  -   630  3
12F  -   650  3


On Sat, Dec 3, 2011 at 7:06 AM, Sarah Goslee sarah.gos...@gmail.com wrote:
 I doubt your data frame looks like that, with all the -, but regardless you
 can use ifelse() to construct your column.

 Sarah

 On Saturday, December 3, 2011, syrvn ment...@gmx.net wrote:
 Hello!

 I have a data.frame which looks like:

 Name - Value
 A - 400
 A - 300
 B - 200
 B - 350
 C - 500
 C - 350
 D - 450
 D - 600
 E - 700
 E - 750
 F - 630
 F - 650

 I want to add another column where all A,B should get an index 1, all C,D
 an
 index of 2 and all E,F an index of 3 so that the data.frame looks like:

 ID - Name - Value
 1 - A - 400
 1 - A - 300
 1 - B - 200
 1 - B - 350
 2 - C - 500
 2 - C - 350
 2 - D - 450
 2 - D - 600
 3 - E - 700
 3 - E - 750
 3 - F - 630
 3 - F - 650

 My data.frame is quite big so I cannot add all values by hand.


 Cheers




 --
 View this message in context:
 http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153024.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.


 --
 Sarah Goslee
 http://www.stringpage.com
 http://www.sarahgoslee.com
 http://www.functionaldiversity.org

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] Reading multiple text files and then combining into a dataframe

2011-12-03 Thread jim holtman
Does this do it for you:

 #Creating example data in similar format to data I have
 sub - rep(1,10)
 trial - seq(1,10,1)
 size - rep(3,10)
 shortest - rep(444,10)
 startlab - rep(444,10)
 endlab - rep(444,10)
 startconf - rep(444,10)
 endconf - rep(444,10)
 steps - sample(1:30,10)
 time - sample(1:300,10)

 #creating example of text file and saving into a shared director with other 
 txt files

 subject1 -
+ cbind(sub,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
 write.table(subject1, /temp/subject1.txt, sep= )

 #2nd example of same text file
 sub - rep(2,10)
 trial - seq(1,10,1)
 size - rep(3,10)
 shortest - rep(444,10)
 startlab - rep(444,10)
 endlab - rep(444,10)
 startconf - rep(444,10)
 endconf - rep(444,10)
 steps - sample(1:30,10)
 time - sample(1:300,10)

 subject1 -
+ cbind(sub,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
 write.table(subject1, /temp/subject2.txt, sep= )


 setwd(/temp)

 #Getting list of file names
 file_name - list.files(pattern=subject*)

 mydata - lapply (file_name, read.table, sep= , header=T, row.names=NULL)

 # rbind to dataframe
 mydf - do.call(rbind, mydata)

 # or use the plyr package
 require(plyr)
 mydf.1 - ldply(file_name, read.table, sep = ' ', header = TRUE, row.names = 
 NULL)

 str(mydf)
'data.frame':   20 obs. of  11 variables:
 $ row.names: chr  1 2 3 4 ...
 $ sub  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ trial: int  1 2 3 4 5 6 7 8 9 10 ...
 $ size : int  3 3 3 3 3 3 3 3 3 3 ...
 $ shortest : int  444 444 444 444 444 444 444 444 444 444 ...
 $ startlab : int  444 444 444 444 444 444 444 444 444 444 ...
 $ endlab   : int  444 444 444 444 444 444 444 444 444 444 ...
 $ startconf: int  444 444 444 444 444 444 444 444 444 444 ...
 $ endconf  : int  444 444 444 444 444 444 444 444 444 444 ...
 $ steps: int  10 28 20 18 4 21 5 3 8 7 ...
 $ time : int  225 188 205 189 103 227 148 221 275 14 ...
 str(mydf.1)
'data.frame':   20 obs. of  11 variables:
 $ row.names: chr  1 2 3 4 ...
 $ sub  : int  1 1 1 1 1 1 1 1 1 1 ...
 $ trial: int  1 2 3 4 5 6 7 8 9 10 ...
 $ size : int  3 3 3 3 3 3 3 3 3 3 ...
 $ shortest : int  444 444 444 444 444 444 444 444 444 444 ...
 $ startlab : int  444 444 444 444 444 444 444 444 444 444 ...
 $ endlab   : int  444 444 444 444 444 444 444 444 444 444 ...
 $ startconf: int  444 444 444 444 444 444 444 444 444 444 ...
 $ endconf  : int  444 444 444 444 444 444 444 444 444 444 ...
 $ steps: int  10 28 20 18 4 21 5 3 8 7 ...
 $ time : int  225 188 205 189 103 227 148 221 275 14 ...



On Fri, Dec 2, 2011 at 11:51 PM, James Holland holland.ag...@gmail.com wrote:
 I have a multiple text files, separated by a single space, that I need to
 combine into a single data.frame.  Below is the track I'm on using
 list.files to capture the names of the files and then lapply with
 read.table.  But I run into problems making a usable dataframe out of the
 data.


 #Creating example data in similar format to data I have
 sub - rep(1,10)
 trial - seq(1,10,1)
 size - rep(3,10)
 shortest - rep(444,10)
 startlab - rep(444,10)
 endlab - rep(444,10)
 startconf - rep(444,10)
 endconf - rep(444,10)
 steps - sample(1:30,10)
 time - sample(1:300,10)

 #creating example of text file and saving into a shared director with other
 txt files

 subject1 -
 cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
 write.table(subject1, C:Folder/R/subject1.txt, sep= )

 #2nd example of same text file
 sub - rep(2,10)
 trial - seq(1,10,1)
 size - rep(3,10)
 shortest - rep(444,10)
 startlab - rep(444,10)
 endlab - rep(444,10)
 startconf - rep(444,10)
 endconf - rep(444,10)
 steps - sample(1:30,10)
 time - sample(1:300,10)

 subject1 -
 cbind(sub1,trial,size,shortest,startlab,endlab,startconf,endconf,steps,time)
 write.table(subject1, C:Folder/R/subject2.txt, sep= )


 setwd(C:Folder/R/)

 #Getting list of file names
 file_name - list.files(pattern=subject*)

 mydata - lapply (file_name, read.table, sep= , header=T, row.names=NULL)



 Thank you,
 James

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




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] Sweave problem on Mac OS when using umlauts and summary()

2011-12-03 Thread Mark Heckmann
I just noticed that the question has already been answered on the R-help list 
before:

http://r.789695.n4.nabble.com/Sweave-font-problems-with-Signif-codes-lines-td977346.html

Adding the following R line solves the problem:

options(useFancyQuotes = FALSE)

Mark

 
 
 On Fri, Dec 2, 2011 at 4:08 PM, Mark Heckmann mark.heckm...@gmx.de wrote:
 I have the following Sweave file which gets sweaved correctly.
 
 =
 m - lm(y1 ~x1, anscombe)
 summary(m)
 @
 
 I include the sweaved .tex file into another .tex file via include.
 When I use a single umlaut in the .snw file a warning occurs.
 As a result part of the summary output is not contained in the .tex file.
 
 ä
 =
 m - lm(y1 ~x1, anscombe)
 summary(m)
 @
 
 You can now run (pdf)latex on 'ch1.tex'
 Warnmeldungen:
 1: ‘ch1.Snw’ has unknown encoding: assuming Latin-1
 2: ungültige Zeichenkette in Konvertierung der Ausgabe (wrong character in 
 conversion of output)
 
 Interestingly, this error does NOT occur, when I omit the summary(m) 
 statement.
 
 ä
 =
 m - lm(y1 ~x1, anscombe)
 #summary(m)
 @
 
 You can now run (pdf)latex on 'ch1.tex'
 Warnmeldung:
 ‘ch1.Snw’ has unknown encoding: assuming Latin-1
 
 I know that I can prevent this by adding a line at the beginning of the .snw 
 file:
 
 \usepackage[utf8]{inputenc}
 
 ä
 =
 m - lm(y1 ~x1, anscombe)
 summary(m)
 @
 
 This gets sweaved correctly without warnings:
 
 But this solution is not good as it is not the preamble of the .tex document 
 where I add the usepackage line.
 This will cause an error when processing the entire document with tex.
 
 How can I achieve the last result in another way?
 I tried:
 
 Sweave('/Users/markheckmann/Desktop/test_sweave/ch1.Snw', encoding=UFT-8)
 
 But this does not work either when the usepackage line is omitted.
 
 I am stuck here. Can anyone help?
 
 TIA
 Mark
 
 
 
 Mark Heckmann
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.com
 
 
 
 
 
 
 
 
 
 
 
[[alternative HTML version deleted]]
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com











[[alternative HTML version deleted]]

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


Re: [R] Data alignment

2011-12-03 Thread syrvn
Thanks for your suggestions. I will try them.

The - in my original post was actually only there to serve as a separator
so that it is easier for you to see the data structure but apparently it
rather confused you... sorry :)

--
View this message in context: 
http://r.789695.n4.nabble.com/Data-alignment-tp4153024p4153112.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] problems using the thin plate spline method

2011-12-03 Thread Mintewab Bezabih
Dear R users, 

I am a beginner in R trying to apply the thin plate spline method to my climate 
data. I used the example in R to do so, and the lines seem to run fine ( I am 
not getting errors) but I am not getting any output in the form of graph or 
anything. I got a warning message saying that 'surface extends beyond box'. 

Any help is much appreciated. 
thanks 
minti 
__
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 tab separated data from internet

2011-12-03 Thread HC
Thanks for your reply.

I tried to use the  postForm function of RCurl as below but do not have much
clue as to how to go further with what it does. 

library(RCurl)
stn-03015795
myurl-paste(http://ida.water.usgs.gov/ida/available_records.cfm?sn=,stn,sep=;)
mypage1 = readLines(myurl)

# Getting the start and end dates
mypattern = 'td align=center([^]*)/td'
datalines = grep(mypattern, mypage1[124], value=TRUE)

getexpr = function(s,g)substring(s,g,g+attr(g,'match.length')-1)
gg = gregexpr(mypattern, datalines)
matches = mapply(getexpr,datalines,gg)
result = gsub(mypattern,'\\1',matches)
names(result)=NULL
mydates-result[1:2]

result = postForm(myurl,fromdate=mydates[1], todate=mydates[2],rtype=Save
to File, submit1=Retrieve Data)


I tried to read the RCurl's documentation but do not know what functions I
should be using. Are there any  examples available that could be helpful.
Could you point me to those please.

Thanks for the help.
HC

--
View this message in context: 
http://r.789695.n4.nabble.com/Downloading-tab-separated-data-from-internet-tp4152318p4153063.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] replace values

2011-12-03 Thread syrvn
Hello,


imagine the following data.frame:

ID name
1 *_A
2 *_A
3 *_B
4 *_B

* = can be any pattern

I want to replace every row which ends with _A by 1 and every row which ends
by _B with a 0

so that the data.frame looks like the following:

ID name
1 1
2 1
3 0
4 0


Which function do I use best to achieve this?

Cheers,
Syrvn



--
View this message in context: 
http://r.789695.n4.nabble.com/replace-values-tp4153301p4153301.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] replace values

2011-12-03 Thread David Winsemius


On Dec 3, 2011, at 8:41 AM, syrvn wrote:


Hello,


imagine the following data.frame:

ID name
1 *_A
2 *_A
3 *_B
4 *_B

* = can be any pattern

I want to replace every row which ends with _A by 1 and every row  
which ends

by _B with a 0


You can use grep(patt, x, value=TRUE) to return vlaues that can be  
used in the prior answers to your earlier question today.


I would have worked it out and tested the strategy, but you continue  
to fail to produce workable examples and then apologize that  
people are confused by them. We are NOT confused... only annoyed ...  
that you fail to use dput() or code for constructing workable code.


--
David.


so that the data.frame looks like the following:

ID name
1 1
2 1
3 0
4 0


Which function do I use best to achieve this?

Cheers,
Syrvn



--
View this message in context: 
http://r.789695.n4.nabble.com/replace-values-tp4153301p4153301.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.


David Winsemius, MD
West Hartford, CT

__
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 installing Rtools

2011-12-03 Thread stillerfan
Great, thanks for answering this basic question.

On Sat, Dec 3, 2011 at 5:12 AM, Duncan Murdoch-2 [via R] 
ml-node+s789695n4152880...@n4.nabble.com wrote:

 On 11-12-02 10:25 PM, stillerfan wrote:
  I'm a new user to R and recently installed R 2.14  for Windows 7 (64
 bit).  I
  have downloaded and ran Rtools 2.14 but do not see any new packages in
 the
  install packages section of R.  I installed Rtools in a subdirectory to
 the
  /library/ directory.  Does anyone have any idea what I could be doing
 wrong?
 

 Rtools doesn't contain R packages, it contains various compilers and
 tools that you could use to build R and R packages.  So you should
 install it in its own directory.  I usually use c:/Rtools.

 Duncan Murdoch

 __
 [hidden email] http://user/SendEmail.jtp?type=nodenode=4152880i=0mailing 
 list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 --
  If you reply to this email, your message will be added to the discussion
 below:

 http://r.789695.n4.nabble.com/Problem-installing-Rtools-tp4152013p4152880.html
  To unsubscribe from Problem installing Rtools, click 
 herehttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4152013code=bWFub2hhcmFuLmFydW5AZ21haWwuY29tfDQxNTIwMTN8ODM3MzcwMTE2
 .
 NAMLhttp://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespacebreadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml



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

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


Re: [R] problems using the thin plate spline method

2011-12-03 Thread Jeff Newmiller
I can tell that you are puzzled and confused. Unfortunately, I am not psychic, 
so I cannot tell what you did, and therefore cannot tell where you went astray.

The solution is for you to read the posting guide mentioned at the bottom of 
every R-help message. Spend a little time to create a small bit of data like 
yours if your actual data is large (subset and dput are useful for this). 
Remember to include the output of sessionInfo, and so on. Many times you are 
likely to find the answer yourself by going through these steps, but they are 
essential for communication.

Good luck.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Mintewab Bezabih mintewab.beza...@economics.gu.se wrote:

Dear R users, 

I am a beginner in R trying to apply the thin plate spline method to my
climate data. I used the example in R to do so, and the lines seem to
run fine ( I am not getting errors) but I am not getting any output in
the form of graph or anything. I got a warning message saying that
'surface extends beyond box'. 

Any help is much appreciated. 
thanks 
minti 
__
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] Iteration in R

2011-12-03 Thread Martin Zonyrah
Hi,
I need help. I am trying to iterate this command  x - rnorm(100, 1.0, 2.0) one 
hundred times in R but I don't seem to have a clue.
Can anyone help?
Your help is very much appreciated.

Martin

[[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] Problem with loop

2011-12-03 Thread Komine
Hi, 
Thank Michael for your help.
Komine

--
View this message in context: 
http://r.789695.n4.nabble.com/Problem-with-loop-tp4148083p4154147.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] Iteration in R

2011-12-03 Thread R. Michael Weylandt
? replicate

or a for loop

or do all one hundred simulations at once

x - matrix(rnorm(100^2, 1, 2), 100)

It's going to depend on what you want to do with the numbers.

Michael

On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah martin20...@yahoo.com wrote:
 Hi,
 I need help. I am trying to iterate this command  x - rnorm(100, 1.0, 2.0) 
 one hundred times in R but I don't seem to have a clue.
 Can anyone help?
 Your help is very much appreciated.

 Martin

        [[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] Counting the occurences of a charater within a string

2011-12-03 Thread Hadley Wickham
On Thu, Dec 1, 2011 at 10:32 AM, Douglas Esneault
douglas.esnea...@mecglobal.com wrote:
 I am new to R but am experienced SAS user and I was hoping to get some help 
 on counting the occurrences of a character within a string at a row level.

 My dataframe, x,  is structured as below:

 Col1
 abc/def
 ghi/jkl/mno

 I found this code on the board but it counts all occurrences of / in the 
 dataframe.

 chr.pos - which(unlist(strsplit(x,NULL))=='/')
 chr.count - length(chr.pos)
 chr.count
 [1] 3

 I'd like to append a column, say cnt, that has the count of / for each row.

Here's an easy way from stringr:

library(stringr)
str_count( c(abc/def, ghi/jkl/mno), /)
# [1] 1 2

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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] Iteration in R

2011-12-03 Thread David Winsemius


On Dec 3, 2011, at 1:10 PM, Martin Zonyrah wrote:


Hi,
I need help. I am trying to iterate this command  x - rnorm(100,  
1.0, 2.0) one hundred times in R but I don't seem to have a clue.


?replicate




==

David Winsemius, MD
West Hartford, CT

__
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] Iteration in R

2011-12-03 Thread andrija djurovic
Hi. One approach is using replicate. See ?replicate:

replicate(3,rnorm(100,1,2))

Andrija

On Sat, Dec 3, 2011 at 7:10 PM, Martin Zonyrah martin20...@yahoo.comwrote:

 Hi,
 I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
 2.0) one hundred times in R but I don't seem to have a clue.
 Can anyone help?
 Your help is very much appreciated.

 Martin

[[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] Iteration in R

2011-12-03 Thread B77S
Hi Michael, 
How would you do this with lapply to return a list?
I can't seem to get that to work (I haven't used these much and am trying to
learn).
Thanks
Brad


Michael Weylandt wrote
 
 ? replicate
 
 or a for loop
 
 or do all one hundred simulations at once
 
 x - matrix(rnorm(100^2, 1, 2), 100)
 
 It's going to depend on what you want to do with the numbers.
 
 Michael
 
 On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt; wrote:
 Hi,
 I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
 2.0) one hundred times in R but I don't seem to have a clue.
 Can anyone help?
 Your help is very much appreciated.

 Martin

        [[alternative HTML version deleted]]


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

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


--
View this message in context: 
http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.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] Iteration in R

2011-12-03 Thread andrija djurovic
Hi Brad. Maybe something like this:

lapply(rep(1,6), function(x) rnorm(10,0,1))

Andrija

On Sat, Dec 3, 2011 at 8:21 PM, B77S bps0...@auburn.edu wrote:

 Hi Michael,
 How would you do this with lapply to return a list?
 I can't seem to get that to work (I haven't used these much and am trying
 to
 learn).
 Thanks
 Brad


 Michael Weylandt wrote
 
  ? replicate
 
  or a for loop
 
  or do all one hundred simulations at once
 
  x - matrix(rnorm(100^2, 1, 2), 100)
 
  It's going to depend on what you want to do with the numbers.
 
  Michael
 
  On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt;
 wrote:
  Hi,
  I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
  2.0) one hundred times in R but I don't seem to have a clue.
  Can anyone help?
  Your help is very much appreciated.
 
  Martin
 
 [[alternative HTML version deleted]]
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.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.


[[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] Iteration in R

2011-12-03 Thread B77S
Interesting and thank you; I'm confused as to why this doesn't work with: 

lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1) 



andrija djurovic wrote
 
 Hi Brad. Maybe something like this:
 
 lapply(rep(1,6), function(x) rnorm(10,0,1))
 
 Andrija
 
 On Sat, Dec 3, 2011 at 8:21 PM, B77S lt;bps0002@gt; wrote:
 
 Hi Michael,
 How would you do this with lapply to return a list?
 I can't seem to get that to work (I haven't used these much and am trying
 to
 learn).
 Thanks
 Brad


 Michael Weylandt wrote
 
  ? replicate
 
  or a for loop
 
  or do all one hundred simulations at once
 
  x - matrix(rnorm(100^2, 1, 2), 100)
 
  It's going to depend on what you want to do with the numbers.
 
  Michael
 
  On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt;
 wrote:
  Hi,
  I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
  2.0) one hundred times in R but I don't seem to have a clue.
  Can anyone help?
  Your help is very much appreciated.
 
  Martin
 
 [[alternative HTML version deleted]]
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


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

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

 
   [[alternative HTML version deleted]]
 
 __
 R-help@ mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.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] Iteration in R

2011-12-03 Thread R. Michael Weylandt
And with replicate:

replicate(100, rnorm(100, 1,2), simplify = FALSE)


Michael

On Sat, Dec 3, 2011 at 2:38 PM, andrija djurovic djandr...@gmail.com wrote:
 Hi Brad. Maybe something like this:

 lapply(rep(1,6), function(x) rnorm(10,0,1))

 Andrija

 On Sat, Dec 3, 2011 at 8:21 PM, B77S bps0...@auburn.edu wrote:

 Hi Michael,
 How would you do this with lapply to return a list?
 I can't seem to get that to work (I haven't used these much and am trying
 to
 learn).
 Thanks
 Brad


 Michael Weylandt wrote
 
  ? replicate
 
  or a for loop
 
  or do all one hundred simulations at once
 
  x - matrix(rnorm(100^2, 1, 2), 100)
 
  It's going to depend on what you want to do with the numbers.
 
  Michael
 
  On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt;
 wrote:
  Hi,
  I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
  2.0) one hundred times in R but I don't seem to have a clue.
  Can anyone help?
  Your help is very much appreciated.
 
  Martin
 
         [[alternative HTML version deleted]]
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


 --
 View this message in context:
 http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.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.


        [[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] Iteration in R

2011-12-03 Thread R. Michael Weylandt
Because lapply() tries to pass an argument to FUN and there's none
that it can receive.

This would work however:

lapply(rep(100, 6), rnorm, mean = 1, sd = 2)

Michael

On Sat, Dec 3, 2011 at 2:42 PM, B77S bps0...@auburn.edu wrote:
 Interesting and thank you; I'm confused as to why this doesn't work with:

 lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1)



 andrija djurovic wrote

 Hi Brad. Maybe something like this:

 lapply(rep(1,6), function(x) rnorm(10,0,1))

 Andrija

 On Sat, Dec 3, 2011 at 8:21 PM, B77S lt;bps0002@gt; wrote:

 Hi Michael,
 How would you do this with lapply to return a list?
 I can't seem to get that to work (I haven't used these much and am trying
 to
 learn).
 Thanks
 Brad


 Michael Weylandt wrote
 
  ? replicate
 
  or a for loop
 
  or do all one hundred simulations at once
 
  x - matrix(rnorm(100^2, 1, 2), 100)
 
  It's going to depend on what you want to do with the numbers.
 
  Michael
 
  On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt;
 wrote:
  Hi,
  I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
  2.0) one hundred times in R but I don't seem to have a clue.
  Can anyone help?
  Your help is very much appreciated.
 
  Martin
 
         [[alternative HTML version deleted]]
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
  __
  R-help@ mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


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

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


       [[alternative HTML version deleted]]

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



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.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] Moving column averaging

2011-12-03 Thread B77S
I don't know the answer, but would suppose not.
You could test this for yourself using:
system.time()
example: 
system.time(rnorm(10,0,1)) 


Chega wrote
 
 This solved my problem - Thanks a lot for your help! Please allow me one
 more question: Works zoo's rollapply on a plain matrix faster than on a
 zoo object? I am asking since I wanted to apply the provided averaging
 code to a larger matrix (2500 rows x 200 cols), which is quite time
 consuming...
 
 Thanks again!
 
 Chega
 
 
 From: B77S [via R] lt;ml-node+s789695n4143909h3@.nabblegt;
 To: Chega lt;chegaga@gt; 
 Sent: Friday, December 2, 2011 6:16 AM
 Subject: Re: Moving column averaging
 
 
 Sorry for that, and thanks Gabor, 
 I could have sworn that it wouldn't. 
 
 
 
 Gabor Grothendieck wrote
On Thu, Dec 1, 2011 at 7:13 PM, B77S [hidden email] wrote: 
 # need zoo to use rollapply() 
 
 # your data (I called df) 
 df - structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), 
    e = c(1L, 5L), f = c(4, 7)), .Names = c(a, b, c, d, 
 e, f), class = data.frame, row.names = c(NA, -2L)) 
 
 # transpose and make a zoo object 
 df2 - zoo(t(df)) 
 
 #rollapply to get means and transpose back 
 means - t(rollapply(df2, width=2, by=2, FUN=mean)) 
 
 # adding the combined column names you requested 
 colnames(means) - apply(matrix(names(df), nrow=2), 2, paste,
 collapse=, ) 
 

Note that zoo's rollapply also works on plain matrices and vectors. 

-- 
Statistics  Software Consulting 
GKX Group, GKX Associates Inc. 
tel: 1-877-GKX-GROUP 
email: ggrothendieck at gmail.com 

__ 
[hidden email] mailing list 
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code. 
 
 
 
 If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143909.html
 To unsubscribe from Moving column averaging, click here.
 NAML
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4154770.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] Shading the plot

2011-12-03 Thread avinash barnwal
Hi all,

I have been trying to shade the specific part of the plot

Part to be shaded

1. Any color whenever a2a3

2. Any other color( Not same as 1) whenever a2a3

Suggest me some code for this task

PLOT CODE for reference

##
a2-c(81.96392786,81.96392786,82.16432866,82.56513026,82.76553106,79.96593186,78.16633267,
75.56713427,74.76753507,72.96793587,70.96793587,45.96793587,83.96793587,84.36873747,
84.56913828,84.56913828,84.56913828,84.56913828,84.36873747,84.36873747)
a3-c(81.96392786,81.96392786,81.96392786,70.96392786,68.16432866,66.16432866,
62.16432866,58.56513026,56.56513026,54.56513026,48.56513026,49.76553106,52.76553106,
54.76553106,57.96593186,59.36673347,83.36673347,83.36673347,83.36673347,
83.56713427)
plot(a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
lines(a3,col='blue',ylab='',xlab= )
##

Thank you in the advance
-- 
Avinash Barnwal
Final year undergraduate student
Statistics and informatics
Department of Mathematics
IIT Kharagpur
attachment: Plot.png__
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] Shading the plot

2011-12-03 Thread R. Michael Weylandt
? polygon
example(polygon)

Michael

On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal
avinashbarnwal...@gmail.com wrote:
 Hi all,

 I have been trying to shade the specific part of the plot

 Part to be shaded

 1. Any color whenever a2a3

 2. Any other color( Not same as 1) whenever a2a3

 Suggest me some code for this task

 PLOT CODE for reference

 ##
 a2-c(81.96392786,81.96392786,82.16432866,82.56513026,82.76553106,79.96593186,78.16633267,
 75.56713427,74.76753507,72.96793587,70.96793587,45.96793587,83.96793587,84.36873747,
 84.56913828,84.56913828,84.56913828,84.56913828,84.36873747,84.36873747)
 a3-c(81.96392786,81.96392786,81.96392786,70.96392786,68.16432866,66.16432866,
 62.16432866,58.56513026,56.56513026,54.56513026,48.56513026,49.76553106,52.76553106,
 54.76553106,57.96593186,59.36673347,83.36673347,83.36673347,83.36673347,
 83.56713427)
 plot(a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
 lines(a3,col='blue',ylab='',xlab= )
 ##

 Thank you in the advance
 --
 Avinash Barnwal
 Final year undergraduate student
 Statistics and informatics
 Department of Mathematics
 IIT Kharagpur

 __
 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] Data Analysis for Gas Prices

2011-12-03 Thread inferno846
Hi there,

I'm looking to analyze a set of data on local gas prices for a single day.
I'm wondering what kind of questions I should be looking to ask and how to
find and answer to them with R. Examples would be: 

Do prices differ between brands?
Does location affect (NE, NW, SE, SW) price?
Does the number of nearby (within .25 miles) competitors affect price?
Do gas stations near shopping centers or highways have different prices?

Also, could anyone help me figure out how to import a data table to R? When
I try to create a .txt file from a word document and read it in R, the
format of the first column always messes up. Any/all help is appreciated.

--
View this message in context: 
http://r.789695.n4.nabble.com/Data-Analysis-for-Gas-Prices-tp4155078p4155078.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] Shading the plot

2011-12-03 Thread avinash barnwal
Hi Weylandt,


I tried it but i was not successful.

Here is the full code

Any help would be great.

time-c(02-Jan-05,09-Jan-05,16-Jan-05,23-Jan-05,30-Jan-05,06-Feb-05,13-Feb-05,20-Feb-05,27-Feb-05,06-Mar-05,13-Mar-05,
20-Mar-05,27-Mar-05,03-Apr-05,10-Apr-05,17-Apr-05,24-Apr-05,01-May-05,08-May-05,15-May-05)
time-as.Date(time,%d-%b-%y)
a2-c(81.96392786,81.96392786,82.16432866,82.56513026,82.76553106,79.96593186,78.16633267,
75.56713427,74.76753507,72.96793587,70.96793587,45.96793587,83.96793587,84.36873747,
84.56913828,84.56913828,84.56913828,84.56913828,84.36873747,84.36873747)
a3-c(81.96392786,81.96392786,81.96392786,70.96392786,68.16432866,66.16432866,
62.16432866,58.56513026,56.56513026,54.56513026,48.56513026,49.76553106,52.76553106,
54.76553106,57.96593186,59.36673347,83.36673347,83.36673347,83.36673347,
83.56713427)
j-0
for(i in 1:length(a3))
{
if(a2[i]a3[i])
{
j-j+1
x[j]-a2[i]
y[j]-a3[i]
temp_time[j]-time[i]
}
}
plot(time,a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
lines(time,a3,col='blue',ylab='',xlab= )
polygon(c(temp_time,rev(temp_time)),c(x,y),col=grey)
#
On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:

 ? polygon
 example(polygon)

 Michael

 On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal
 avinashbarnwal...@gmail.com wrote:
  Hi all,
 
  I have been trying to shade the specific part of the plot
 
  Part to be shaded
 
  1. Any color whenever a2a3
 
  2. Any other color( Not same as 1) whenever a2a3
 
  Suggest me some code for this task
 
  PLOT CODE for reference
 
 
 ##
 
 a2-c(81.96392786,81.96392786,82.16432866,82.56513026,82.76553106,79.96593186,78.16633267,
 
 75.56713427,74.76753507,72.96793587,70.96793587,45.96793587,83.96793587,84.36873747,
 
 84.56913828,84.56913828,84.56913828,84.56913828,84.36873747,84.36873747)
 
 a3-c(81.96392786,81.96392786,81.96392786,70.96392786,68.16432866,66.16432866,
 
 62.16432866,58.56513026,56.56513026,54.56513026,48.56513026,49.76553106,52.76553106,
 
 54.76553106,57.96593186,59.36673347,83.36673347,83.36673347,83.36673347,
  83.56713427)
  plot(a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
  lines(a3,col='blue',ylab='',xlab= )
 
 ##
 
  Thank you in the advance
  --
  Avinash Barnwal
  Final year undergraduate student
  Statistics and informatics
  Department of Mathematics
  IIT Kharagpur
 
  __
  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.
 




-- 
Avinash Barnwal
Final year undergraduate student
Statistics and informatics
Department of Mathematics
IIT Kharagpur

[[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] pivot table help

2011-12-03 Thread set
Hello R-users,

I've got a huge table with about 20.00 rows and 50 columns. The table now
has headers as Members1, Members2 etc. My data are 8 different individuals.
And I've got a column with clusters. So each individual belongs to different
clusters and can occurs multiple times within a cluster (that's the reason
that there can be more than 8 members). I want a presence/ absence table for
each individual within each cluster.
So I want to go from:
Cluster   Member1Member2  etc.
1ind1   ind2
2ind3   ind1
3ind2   ind1

to

clusterind1  ind2  ind3
11   1  0
210 1
31   1  0

Has anybody any idea how I can do this? I already tried alot of things with
pivottables (using cast()) But I think I'm missing out on something.
thank you

--
View this message in context: 
http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.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] Data Analysis for Gas Prices

2011-12-03 Thread B77S
use a  ?  to get help on a function; example:

?read.table

If you do this you will see an option called header...  
use header=T if your top row contains column names.  

Learn how to read these help pages.  Also, read thru a few beginner R
manuals and see this website:
http://www.statmethods.net/interface/io.html

As for the rest of your questions. 
Perhaps this is your sign to begin reading a intro-stats book, or inquire on
a different forum.
see:
http://stats.stackexchange.com/questions

good luck


inferno846 wrote
 
 Hi there,
 
 I'm looking to analyze a set of data on local gas prices for a single day.
 I'm wondering what kind of questions I should be looking to ask and how to
 find and answer to them with R. Examples would be: 
 
 Do prices differ between brands?
 Does location affect (NE, NW, SE, SW) price?
 Does the number of nearby (within .25 miles) competitors affect price?
 Do gas stations near shopping centers or highways have different prices?
 
 Also, could anyone help me figure out how to import a data table to R?
 When I try to create a .txt file from a word document and read it in R,
 the format of the first column always messes up. Any/all help is
 appreciated.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Data-Analysis-for-Gas-Prices-tp4155078p4155185.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] pivot table help

2011-12-03 Thread Richard M. Heiberger
Pivot tables are an Excel concept, not an R concept.

That means you must give an example of your starting pivot table as an R
object (use dump() so we can pick it up from the email and execute it
immediately).
and an example of the R object you want as the result.
Use a trivial but complete example.

An example of dump

tmp - matrix(1:6,2,3)
tmp
dump(tmp,)
Be sure to read the posting guide before sending your revised request.

PLEASE do read the posting guide
http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Rich
On Sat, Dec 3, 2011 at 5:27 PM, set asta...@hotmail.com wrote:

 Hello R-users,

 I've got a huge table with about 20.00 rows and 50 columns. The table now
 has headers as Members1, Members2 etc. My data are 8 different individuals.
 And I've got a column with clusters. So each individual belongs to
 different
 clusters and can occurs multiple times within a cluster (that's the reason
 that there can be more than 8 members). I want a presence/ absence table
 for
 each individual within each cluster.
 So I want to go from:
 Cluster   Member1Member2  etc.
 1ind1   ind2
 2ind3   ind1
 3ind2   ind1

 to

 clusterind1  ind2  ind3
 11   1  0
 210 1
 31   1  0

 Has anybody any idea how I can do this? I already tried alot of things with
 pivottables (using cast()) But I think I'm missing out on something.
 thank you

 --
 View this message in context:
 http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.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.htmlhttp://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] pivot table help

2011-12-03 Thread jim holtman
try this:

 x - read.table(text = Cluster   Member1Member2
+ 1ind1   ind2
+ 2ind3   ind1
+ 3ind2   ind1, as.is = TRUE, header = TRUE)
 require(reshape2)
 x.m - melt(x, id = Cluster)
 x.m
  Cluster variable value
1   1  Member1  ind1
2   2  Member1  ind3
3   3  Member1  ind2
4   1  Member2  ind2
5   2  Member2  ind1
6   3  Member2  ind1
 table(x.m$Cluster, x.m$value)

ind1 ind2 ind3
  1110
  2101
  3110



On Sat, Dec 3, 2011 at 5:53 PM, Richard M. Heiberger r...@temple.edu wrote:
 Pivot tables are an Excel concept, not an R concept.

 That means you must give an example of your starting pivot table as an R
 object (use dump() so we can pick it up from the email and execute it
 immediately).
 and an example of the R object you want as the result.
 Use a trivial but complete example.

 An example of dump

 tmp - matrix(1:6,2,3)
 tmp
 dump(tmp,)
 Be sure to read the posting guide before sending your revised request.

 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 Rich
 On Sat, Dec 3, 2011 at 5:27 PM, set asta...@hotmail.com wrote:

 Hello R-users,

 I've got a huge table with about 20.00 rows and 50 columns. The table now
 has headers as Members1, Members2 etc. My data are 8 different individuals.
 And I've got a column with clusters. So each individual belongs to
 different
 clusters and can occurs multiple times within a cluster (that's the reason
 that there can be more than 8 members). I want a presence/ absence table
 for
 each individual within each cluster.
 So I want to go from:
 Cluster   Member1    Member2  etc.
 1            ind1           ind2
 2            ind3           ind1
 3            ind2           ind1

 to

 cluster    ind1          ind2      ind3
 1            1               1          0
 2            1                0         1
 3            1               1          0

 Has anybody any idea how I can do this? I already tried alot of things with
 pivottables (using cast()) But I think I'm missing out on something.
 thank you

 --
 View this message in context:
 http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.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.htmlhttp://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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] pivot table help

2011-12-03 Thread jim holtman
Forgot, you can also do this:

 dcast(x.m, Cluster ~ value, fun = length)
  Cluster ind1 ind2 ind3
1   1110
2   2101
3   3110



On Sat, Dec 3, 2011 at 7:02 PM, jim holtman jholt...@gmail.com wrote:
 try this:

 x - read.table(text = Cluster   Member1    Member2
 + 1            ind1           ind2
 + 2            ind3           ind1
 + 3            ind2           ind1, as.is = TRUE, header = TRUE)
 require(reshape2)
 x.m - melt(x, id = Cluster)
 x.m
  Cluster variable value
 1       1  Member1  ind1
 2       2  Member1  ind3
 3       3  Member1  ind2
 4       1  Member2  ind2
 5       2  Member2  ind1
 6       3  Member2  ind1
 table(x.m$Cluster, x.m$value)

    ind1 ind2 ind3
  1    1    1    0
  2    1    0    1
  3    1    1    0



 On Sat, Dec 3, 2011 at 5:53 PM, Richard M. Heiberger r...@temple.edu wrote:
 Pivot tables are an Excel concept, not an R concept.

 That means you must give an example of your starting pivot table as an R
 object (use dump() so we can pick it up from the email and execute it
 immediately).
 and an example of the R object you want as the result.
 Use a trivial but complete example.

 An example of dump

 tmp - matrix(1:6,2,3)
 tmp
 dump(tmp,)
 Be sure to read the posting guide before sending your revised request.

 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 Rich
 On Sat, Dec 3, 2011 at 5:27 PM, set asta...@hotmail.com wrote:

 Hello R-users,

 I've got a huge table with about 20.00 rows and 50 columns. The table now
 has headers as Members1, Members2 etc. My data are 8 different individuals.
 And I've got a column with clusters. So each individual belongs to
 different
 clusters and can occurs multiple times within a cluster (that's the reason
 that there can be more than 8 members). I want a presence/ absence table
 for
 each individual within each cluster.
 So I want to go from:
 Cluster   Member1    Member2  etc.
 1            ind1           ind2
 2            ind3           ind1
 3            ind2           ind1

 to

 cluster    ind1          ind2      ind3
 1            1               1          0
 2            1                0         1
 3            1               1          0

 Has anybody any idea how I can do this? I already tried alot of things with
 pivottables (using cast()) But I think I'm missing out on something.
 thank you

 --
 View this message in context:
 http://r.789695.n4.nabble.com/pivot-table-help-tp4155144p4155144.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.htmlhttp://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.



 --
 Jim Holtman
 Data Munger Guru

 What is the problem that you are trying to solve?
 Tell me what you want to do, not how you want to do it.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
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] help in removal of fixed pattern

2011-12-03 Thread D. Schruth


A great function for extracting pattern matches is 'm()'

library(caroline)
vect - m('([xX][0-9])',df$Input)
toupper(vect)  #in case you really want all upper case x's

It does the hard work of using 'sub' to remove the non-matching parts 
(sub, grep, regexpr, etc aren't very good for this sort of thing)


It also can return a data.frame if you have multiple patterns you wish to 
match in each string vector element.


-Dave


On Fri, 2 Dec 2011, arunkumar wrote:


Hi

I have column name as given below

If the variable is in log(X1 + 1) pattern it should be removed and i need
only X1

Input
log(x1 + 1)
x2
log(X3 +1)

Expected Output X1 X2 X3

Please help me


--
View this message in context: 
http://r.789695.n4.nabble.com/help-in-removal-of-fixed-pattern-tp4152524p4152524.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] Shading the plot

2011-12-03 Thread David Winsemius


On Dec 3, 2011, at 5:28 PM, avinash barnwal wrote:


Hi Weylandt,


I tried it but i was not successful.

Here is the full code

Any help would be great.

time-c(02-Jan-05,09-Jan-05,16-Jan-05,23-Jan-05,30- 
Jan-05,06-Feb-05,13-Feb-05,20-Feb-05,27-Feb-05,06- 
Mar-05,13-Mar-05,
20-Mar-05,27-Mar-05,03-Apr-05,10-Apr-05,17-Apr-05,24- 
Apr-05,01-May-05,08-May-05,15-May-05)

time-as.Date(time,%d-%b-%y)
a2- 
c 
(81.96392786 
,81.96392786 
,82.16432866 
,82.56513026,82.76553106,79.96593186,78.16633267,
75.56713427 
,74.76753507 
,72.96793587 
,70.96793587,45.96793587,83.96793587,84.36873747,
84.56913828 
,84.56913828 
,84.56913828,84.56913828,84.36873747,84.36873747)
a3- 
c 
(81.96392786 
,81.96392786 
,81.96392786,70.96392786,68.16432866,66.16432866,
62.16432866 
,58.56513026 
,56.56513026 
,54.56513026,48.56513026,49.76553106,52.76553106,
54.76553106 
,57.96593186 
,59.36673347,83.36673347,83.36673347,83.36673347,

83.56713427)
j-0
for(i in 1:length(a3))
{
if(a2[i]a3[i])
{
j-j+1
x[j]-a2[i]
y[j]-a3[i]
temp_time[j]-time[i]
}
}
plot(time,a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
lines(time,a3,col='blue',ylab='',xlab= )
polygon(c(temp_time,rev(temp_time)),c(x,y),col=grey)
#


What are the rules that govern requesting outside help in homework at  
your institution?


Your current code does not recognize  that there is line crossing. Nor  
do you describe what you mean by shading. If you wanted a rectangle  
within the lpot area it would drive one strategy and if you wanted  
only the area between the curves to be shaded it would drive a  
different strategy.


AND you never define x or y.

--
David.




On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt 
michael.weyla...@gmail.com wrote:


? polygon
example(polygon)

Michael

On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal
avinashbarnwal...@gmail.com wrote:

Hi all,

I have been trying to shade the specific part of the plot

Part to be shaded

1. Any color whenever a2a3

2. Any other color( Not same as 1) whenever a2a3

Suggest me some code for this task

PLOT CODE for reference



##


a2- 
c 
(81.96392786 
,81.96392786 
,82.16432866 
,82.56513026,82.76553106,79.96593186,78.16633267,


75.56713427 
,74.76753507 
,72.96793587 
,70.96793587,45.96793587,83.96793587,84.36873747,


84.56913828 
,84.56913828 
,84.56913828,84.56913828,84.36873747,84.36873747)


a3- 
c 
(81.96392786 
,81.96392786 
,81.96392786,70.96392786,68.16432866,66.16432866,


62.16432866 
,58.56513026 
,56.56513026 
,54.56513026,48.56513026,49.76553106,52.76553106,


54.76553106 
,57.96593186 
,59.36673347,83.36673347,83.36673347,83.36673347,

83.56713427)
plot(a2,type='l',col='red',ylab='',xlab= ,axes=FALSE)
lines(a3,col='blue',ylab='',xlab= )


##


Thank you in the advance
--
Avinash Barnwal
Final year undergraduate student
Statistics and informatics
Department of Mathematics
IIT Kharagpur

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







--
Avinash Barnwal
Final year undergraduate student
Statistics and informatics
Department of Mathematics
IIT Kharagpur

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


David Winsemius, MD
West Hartford, CT

__
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] rnorm command

2011-12-03 Thread Cheryl Johnson
Hello,

I use the command rnorm, and I feed these results into a lmer command.
Since I am using the rnorm command I expect to get different results for
each iteration, yet for each iteration I am getting the same answer. If
someone understands why I am getting the same answer every time with a
random number generator, I would appreciate help in understanding why this
is happening. Is the lmer command causing the answer to be the same each
time?

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] density function always evaluating to zero

2011-12-03 Thread napps22
Dear R users,

I'm trying to carry out monte carlo integration of a posterior density
function which is the product of a normal and a gamma distribution. The
problem I have is that the density function always returns 0. How can I
solve this problem?

Here is my code

#generate data

x1 - runif(100, min = -10, max = 10)
y - 2 * x1^2 + rnorm(100)

# # # # # # # # Model 0 # # # # # # # 

z - x1^2
M - sum(z^2)
MI - 1/M
zy - crossprod(z,y)
alpha.ols - MI * zy
resid_m0 - y - z * alpha.ols
s2_m0 - sum(resid_m0^2)/v

# use gibbs sampler to sample from posterior densities

n - length(y)
k - 1
v - n - k

# set up gibbs sampler

nrDraws - 1
h_sample_m0 - rgamma(nrDraws, v/2, v*s2_m0/2) 
alpha_sample - matrix(0, nrow = nrDraws, ncol = 1)

for(i in 1:nrDraws) {

alpha_sample[i] - rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI)

}

# define posterior density for model 0

f - function(alpha,h) {

e - y - alpha * x1^2
const - (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m1/2)^(-v/2) )  
kernel - h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h)
x - const * kernel
return(x)
}

# calculate approximation of p(y|m_0)

m0 -f(alpha_sample,h_sample_m0)
post_m0 - sum(m0) / nrDraws
 

--
View this message in context: 
http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4155181.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] Logistic Regression with genetic component

2011-12-03 Thread Danielle Duncan
Greetings, I have a question that I'd like to get input on. I have a
classic toxicology study where I artificially fertilized and exposed
embryos to a chemical and counted defects. In addition, I kept track of
male-female pairs that I used to artificially fertilize and generate
embryos with. I need to use logistic regression to model the response, but
also check that the genetics of the pairings did or did not have an effect
on the response. My data looks a bit like this:

response matrix chemical concentration  Genetic Matrix
Present AbsentMale Female
2 152   0.13 a 1
6 121  1 a 2
21 92  2 b 3
24 89  5 b 4
0141 10 c 5
5 95 15 c  6

R code:

DA-cbind(Present, Absent)
glm-(DA ~ chemical concentration)

If I do glm-(DA ~ chemical concentration + Male + Female, I get every
possible combination, but I only want specific pairs. So, I am thinking
about doing:

MF-cbind(Male, Female)
glm-(DA ~ chemical concentration + MF)

Is this correct? Any help on how to model this would be greatly
appreciated! Thanks in advance!

[[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] Shading the plot

2011-12-03 Thread avinash barnwal
Hi,

I apologies  for my naive doubts
I have been trying it from a while. I need the area between the curve based
on conditions i wrote (whenever red line is above the blue line then area
between curves to be grey color and whenever blue line is above red line
then area between curves to be red color )

x and y are vectors

Thank you for replying



On Sun, Dec 4, 2011 at 7:56 AM, David Winsemius dwinsem...@comcast.netwrote:


 On Dec 3, 2011, at 5:28 PM, avinash barnwal wrote:

  Hi Weylandt,


 I tried it but i was not successful.

 Here is the full code

 Any help would be great.
 ##**##**
 
 time-c(02-Jan-05,09-Jan-**05,16-Jan-05,23-Jan-05,**
 30-Jan-05,06-Feb-05,13-**Feb-05,20-Feb-05,27-Feb-**
 05,06-Mar-05,13-Mar-05,
 20-Mar-05,27-Mar-05,03-**Apr-05,10-Apr-05,17-Apr-**
 05,24-Apr-05,01-May-05,**08-May-05,15-May-05)
 time-as.Date(time,%d-%b-%y)
 a2-c(81.96392786,81.**96392786,82.16432866,82.**
 56513026,82.76553106,79.**96593186,78.16633267,
 75.56713427,74.76753507,**72.96793587,70.96793587,**
 45.96793587,83.96793587,**84.36873747,
 84.56913828,84.56913828,**84.56913828,84.56913828,**
 84.36873747,84.36873747)
 a3-c(81.96392786,81.**96392786,81.96392786,70.**
 96392786,68.16432866,66.**16432866,
 62.16432866,58.56513026,**56.56513026,54.56513026,**
 48.56513026,49.76553106,**52.76553106,
 54.76553106,57.96593186,**59.36673347,83.36673347,**
 83.36673347,83.36673347,
 83.56713427)
 j-0
 for(i in 1:length(a3))
 {
 if(a2[i]a3[i])
 {
 j-j+1
 x[j]-a2[i]
 y[j]-a3[i]
 temp_time[j]-time[i]
 }
 }
 plot(time,a2,type='l',col='**red',ylab='',xlab= ,axes=FALSE)
 lines(time,a3,col='blue',ylab=**'',xlab= )
 polygon(c(temp_time,rev(temp_**time)),c(x,y),col=grey)
 ##**##**
 #


 What are the rules that govern requesting outside help in homework at your
 institution?

 Your current code does not recognize  that there is line crossing. Nor do
 you describe what you mean by shading. If you wanted a rectangle within the
 lpot area it would drive one strategy and if you wanted only the area
 between the curves to be shaded it would drive a different strategy.

 AND you never define x or y.

 --
 David.



  On Sun, Dec 4, 2011 at 2:46 AM, R. Michael Weylandt 
 michael.weyla...@gmail.com wrote:

  ? polygon
 example(polygon)

 Michael

 On Sat, Dec 3, 2011 at 4:08 PM, avinash barnwal
 avinashbarnwal...@gmail.com wrote:

 Hi all,

 I have been trying to shade the specific part of the plot

 Part to be shaded

 1. Any color whenever a2a3

 2. Any other color( Not same as 1) whenever a2a3

 Suggest me some code for this task

 PLOT CODE for reference


  ##**##**
 ##**


  a2-c(81.96392786,81.**96392786,82.16432866,82.**
 56513026,82.76553106,79.**96593186,78.16633267,


  75.56713427,74.76753507,**72.96793587,70.96793587,**
 45.96793587,83.96793587,**84.36873747,


  84.56913828,84.56913828,**84.56913828,84.56913828,**
 84.36873747,84.36873747)


  a3-c(81.96392786,81.**96392786,81.96392786,70.**
 96392786,68.16432866,66.**16432866,


  62.16432866,58.56513026,**56.56513026,54.56513026,**
 48.56513026,49.76553106,**52.76553106,


  54.76553106,57.96593186,**59.36673347,83.36673347,**
 83.36673347,83.36673347,

 83.56713427)
 plot(a2,type='l',col='red',**ylab='',xlab= ,axes=FALSE)
 lines(a3,col='blue',ylab='',**xlab= )

  ##**##**
 ##**


 Thank you in the advance
 --
 Avinash Barnwal
 Final year undergraduate student
 Statistics and informatics
 Department of Mathematics
 IIT Kharagpur

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide

 http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html

 and provide commented, minimal, self-contained, reproducible code.





 --
 Avinash Barnwal
 Final year undergraduate student
 Statistics and informatics
 Department of Mathematics
 IIT Kharagpur

[[alternative HTML version deleted]]


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


 David Winsemius, MD
 West Hartford, CT




-- 
Avinash Barnwal
Final year undergraduate student
Statistics and informatics
Department of Mathematics
IIT Kharagpur

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list

[R] Prediction from censReg?

2011-12-03 Thread z2.0
Hi - 

First post, so excuse any errors in protocol: 

Wanted to ask if there's an easy way to use 'predict' with objects of class
'censReg', 'maxLik', 'maxim' or 'list'.

Have a left-censored dataset, attempting to use a Tobit model and am working
with the censReg package. I like how easy it is to move from glm models to
predictions with 'predict' and wanted to ask if there was a way to do so
with objects output from 'censReg'.

Thanks,

Zack

--
View this message in context: 
http://r.789695.n4.nabble.com/Prediction-from-censReg-tp4155855p4155855.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] upper bound in the integrate function depends on a parameter

2011-12-03 Thread grttt nbbfg
Sorry for my English, is not my first language..

I have some trouble in terms of using integrate function in R.
fx is a function of m and x where m is supposed to be a unknown parameter.

fx=function(m,x){
+ x*2/(3*m)*(1-x/(3*m))
+ }

The problem is in upper bound, it depends on parameter m.

integrate(fx,lower=0,upper=3*m)$value

Is it possible to use the integrate function when bounds depend on a
parameter?

How to define m to solve this integral? The result should be m.

[[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] density function always evaluating to zero

2011-12-03 Thread David Winsemius


On Dec 3, 2011, at 5:42 PM, napps22 wrote:


Dear R users,

I'm trying to carry out monte carlo integration of a posterior density
function which is the product of a normal and a gamma distribution.  
The
problem I have is that the density function always returns 0. How  
can I

solve this problem?


Your code throws errors due to several missing objects due in part to  
a missing v, but moving that higher in the code does not cure  
everything.  A missing 's2_m1' is also listed as a source of error.  
You might want to try in a clean session and redo your debugging so  
that you know what variables are in your workspace and their values.


The usual debugging method is to sprinkle print() statements in your  
code to monitor where things might not be proceeding as planned.


--
David.


Here is my code

#generate data

x1 - runif(100, min = -10, max = 10)
y - 2 * x1^2 + rnorm(100)

# # # # # # # # Model 0 # # # # # # #

z - x1^2
M - sum(z^2)
MI - 1/M
zy - crossprod(z,y)
alpha.ols - MI * zy
resid_m0 - y - z * alpha.ols
s2_m0 - sum(resid_m0^2)/v

# use gibbs sampler to sample from posterior densities

n - length(y)
k - 1
v - n - k

# set up gibbs sampler

nrDraws - 1
h_sample_m0 - rgamma(nrDraws, v/2, v*s2_m0/2)
alpha_sample - matrix(0, nrow = nrDraws, ncol = 1)

for(i in 1:nrDraws) {

alpha_sample[i] - rnorm(1,alpha.ols,(1/h_sample_m0[i]) * MI)

}

# define posterior density for model 0

f - function(alpha,h) { 

e - y - alpha * x1^2
const - (2*pi)^(-n/2) / ( gamma(v/2) * (v*s2_m1/2)^(-v/2) )
kernel - h^((v-1)/2) * exp((-(h/2) * sum(e^2)) - (v*s2_m0)*h)
x - const * kernel
return(x)
}

# calculate approximation of p(y|m_0)

m0 -f(alpha_sample,h_sample_m0)
post_m0 - sum(m0) / nrDraws


--
View this message in context: 
http://r.789695.n4.nabble.com/density-function-always-evaluating-to-zero-tp4155181p4155181.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.


David Winsemius, MD
West Hartford, CT

__
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] upper bound in the integrate function depends on a parameter

2011-12-03 Thread David Winsemius


On Dec 3, 2011, at 10:23 PM, grttt nbbfg wrote:


Sorry for my English, is not my first language..

I have some trouble in terms of using integrate function in R.
fx is a function of m and x where m is supposed to be a unknown  
parameter.


R is not an algebraic solver (and R-help is not a homework list.).




fx=function(m,x){

+ x*2/(3*m)*(1-x/(3*m))
+ }

The problem is in upper bound, it depends on parameter m.


integrate(fx,lower=0,upper=3*m)$value


Is it possible to use the integrate function when bounds depend on a
parameter?


If it is known, yes. You could also do some investigation:

curve(x*2/(3*5)*(1-x/(3*5)), 0, 15)



How to define m to solve this integral? The result should be m.


As I said, no homework answers here.

--
David Winsemius, MD
West Hartford, CT

__
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] rnorm command

2011-12-03 Thread Jeff Newmiller
No.

If you want a more informative answer, try following the recommendations in the 
posting guide mentioned below.
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Cheryl Johnson johnson.cheryl...@gmail.com wrote:

Hello,

I use the command rnorm, and I feed these results into a lmer command.
Since I am using the rnorm command I expect to get different results
for
each iteration, yet for each iteration I am getting the same answer. If
someone understands why I am getting the same answer every time with a
random number generator, I would appreciate help in understanding why
this
is happening. Is the lmer command causing the answer to be the same
each
time?

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@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] Assign name to object for each iteration in a loop.

2011-12-03 Thread Patrick Connolly
On Thu, 01-Dec-2011 at 10:13AM -0800, lglew wrote:

| Hi R-users,
| 
| I'm trying to produce decompositions of a multiple time-series, grouped by a
| factor (called area). I'm modifying the code in the STLperArea function of
| package ndvits, as this function only plots produces stl plots, it does not
| return the underlying data. 
| 
| I want to extract the trend component of each decomposition
| (x$time.series[,trend]), assign a name based on the factor area. 
| 
| My input data look like this:
| Area is a factor, with three (but could be many more) levels.
| area
| 1
| 2
| 3
| 
| Ystart=2000
| 
| TS is a timeseries:
| 
|   X249   X265  X281  X297  X2000113 
| 1 0.2080  0.2165  0.2149 0.2314  0.2028  
| 2 0.1578  0.1671  0.1577 0.1593  0.1672   
| 3 0.1897  0.1948  0.2290 0.2292  0.2067   
| 
| Here's the function:
| 
| STLpA-function(TS, area, Ystart, period=23, nSG=5,5, DSG=0)
| {
| require (RTisean)
| for(i in 1:unique(area)){
| vi.metric=TS[area==i]
| filt.vi-sav_gol(vi.metric,n=nSG,D=DSG)
| vi.sg-ts(filt.vi[,1], start=Ystart,frequency=period)
| stld.tmp-stl(vi.sg, s.window=periodic, robust=TRUE, na.action=na.approx)
| stld.trend-stld.temp$time.series[,trend]
| }
| assign(paste(stld, i , sep= .), stld.trend)
| vi.trend-ls(pattern= ^stld..$)
| return(vi.trend)
| }
| 
| When I call this function with signal=STLpA(TS,area,Ystart=2000,period=23,
| nSG= 5,5, DSG=0))
| 
| I get this error:
| 
| Error in cat(list(...), file, sep, fill, labels, append) : 
|   argument 1 (type 'list') cannot be handled by 'cat'
| In addition: Warning message:
| In 1:unique(area) :
|   numerical expression has 3 elements: only the first used
| 
| I'm guessing this is because I'm assigning names to each temporary stl.trend
| file incorrectly. Can anyone 
| improve on my rather poor efforts here?

I would suggest putting your individual trends into a list and
returning that at the end of your function rather than trying to
assing individual objects.  IMHO it's easier to do and more useful.
Something along these lines:


 trends - list()
 for(i in 1:unique(area)){
...
+ trends[[i]] - 

}

Then you'll have an element in the list trends that you do with what
you will.  It creates less clutter also.

HTH



-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

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