Re: [R] Problem with xtabs(), exclude=NULL, and counting NA's

2009-09-05 Thread Mark Difford

>> I must say that this is slightly odd behavior to require both
>> na.action= AND exclude=.  Does anyone know of a justification?

Not strange at all.

?options

na.action, sub head "Options set in package stats." You need to override the
default setting.


ws-7 wrote:
> 
>>> xtabs(~wkhp, x, exclude=NULL, na.action=na.pass)
>> wkhp
>>  20   30   40   45   60 
>>   1    1   10    1    3    4
> 
> Thanks!  I must say that this is slightly odd behavior to require both
> na.action= AND exclude=.  Does anyone know of a justification?
> Shouldn't it be changed?   Ah well, if R were internally
> consistent or corresponded to typical programming Unix practices, it
> just wouldn't feel the same ... 
> 
> Cheers!
> 
>> --
>> David Winsemius, MD
>> Heritage Laboratories
>> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problem-with-xtabs%28%29%2C-exclude%3DNULL%2C-and-counting-NA%27s-tp25304142p25305878.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] What is the difference between read.delim and read.delim2?

2009-09-05 Thread Gabor Grothendieck
In some countries a decimal comma is the norm.

On Fri, Sep 4, 2009 at 6:16 PM, David Winsemius wrote:
> It's pretty subtle, I will admit, but look more carefully at the dec=
> parameter in the help page. Kind of like the historical battles between
> between the Liebnizians and the Newtonians.
>
> On Sep 4, 2009, at 5:58 PM, Peng Yu wrote:
>
>> Hi,
>>
>> I don't see what the difference between read.delim and read.delim2
>> after reading the help. Can somebody let me know what it is?
>>
>> Regards,
>> Peng
>>
>
>
> David Winsemius, MD
> Heritage Laboratories
> 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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How can I appoint a small part of the whole data

2009-09-05 Thread Yichih Hsieh
Dear Petr,

your suggestion is useful

many thanks for your help !


best,
Yichih

2009/9/3 Petr PIKAL 

> Hi
>
> use any of suitable selection ways that are in R.
>
> E.g.
>
> data[data$gender==1, ]
>
> selects only female values
>
> data$wage[(data$gender==1)  & (data$race=1)] selects black female wages.
>
> and see also ?subset
>
> Regards
> Petr
>
> r-help-boun...@r-project.org napsal dne 03.09.2009 10:51:59:
>
> > Dear all,
> >
> > I have 1980~1990 eleven datas,
> > every year have three variables,
> > wage
> > gender(1=female, 2=male)
> > race(1=black, 2=white)
> >
> > My original commands is:
> >
> > fig2b<-reldist(y=mu1990$wage,yo=mu1980$wage,...)
> >
> > I have three questions:
> > 1. If I want to appoint y=women's wage in 1990
> > yo=women's wage in 1980
> > 2. If I want to appoint y=women's wage in 1990
> > yo=men's wage in 1990
> > 3. If I want to appoint y=black women's wage in 1990
> > yo=white women's wage in 1990
> >
> > How can I modify the commands?
> >
> > All help highly appreciated.
> >
> > Best,
> > Yichih
> >
> >
> > --
> > Yichih Hsieh
> >
> > e-mail : yichih.hs...@gmail.com
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>


-- 
Yichih Hsieh

e-mail : yichih.hs...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] Problem accessing functions in package 'roxygen'

2009-09-05 Thread Uwe Ligges



Robert A LaBudde wrote:

Thanks, Uwe. Unfortunately, that doesn't work either:

 > library('roxygen')
Warning message:
package 'roxygen' was built under R version 2.9.1
 > roxygen::trim(' 1234 ')


You need three colons as indicated in my previous answer!

Uwe



Error: 'trim' is not an exported object from 'namespace:roxygen'

I ended up using

trim <- function(x) gsub("^[[:space:]]+|[[:space:]]+$", "", x)

instead.

At 01:42 PM 9/3/2009, Uwe Ligges wrote:



Robert A. LaBudde wrote:
I have Vista Home with R-2.9.0, and installed and tried to test the 
package 'roxygen':

 > utils:::menuInstallPkgs()
trying URL 
'http://lib.stat.cmu.edu/R/CRAN/bin/windows/contrib/2.9/roxygen_0.1.zip'

Content type 'application/zip' length 699474 bytes (683 Kb)
opened URL
downloaded 683 Kb
package 'roxygen' successfully unpacked and MD5 sums checked
The downloaded packages are in
C:\Users\RAL\AppData\Local\Temp\RtmpZPlILq\downloaded_packages
updating HTML package descriptions
Warning message:
In file.create(f.tg) :
  cannot create file 'C:\PROGRA~1\R\R-29~1.0/doc/html/packages.html', 
reason 'Permission denied'

 > library('roxygen')
Warning message:
package 'roxygen' was built under R version 2.9.1
 > trim("  1234")
Error: could not find function "trim"
I have a similar problem with trim.right(), trim.left() and other 
functions I've tried.

Any ideas?


Probably it is not intende to call trim and friends like that, because 
they are not exported from roxygen's namespace, hence you could use 
roxygen:::trim("  1234")


Uwe Ligges




Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: r...@lcfltd.com
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947
"Vere scire est per causas scire"
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html

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



Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: r...@lcfltd.com
Least Cost Formulations, Ltd.URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239Fax: 757-467-2947

"Vere scire est per causas scire"




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Color index in image function

2009-09-05 Thread FMH
Dear All,

I was looking for the color index in image function, such as from 
topo.colors(n) and etc. but still never found it. For instance, from the help 
menu.


###
# Volcano data visualized as matrix. Need to transpose and flip
# matrix horizontally.
image(t(volcano)[ncol(volcano):1,])

# A prettier display of the volcano
x <- 10*(1:nrow(volcano))
y <- 10*(1:ncol(volcano))
image(x, y, volcano, col = terrain.colors(100), axes = FALSE)
contour(x, y, volcano, levels = seq(90, 200, by = 5),
    add = TRUE, col = "peru")
axis(1, at = seq(100, 800, by = 100))
axis(2, at = seq(100, 600, by = 100))
box()
title(main = "Maunga Whau Volcano", font.main = 4)
#

>From the script above, it yields a beautiful  image of volcano with variety of 
>colors but i have to list down the color index that could show the meaning of 
>each color in my thesis. 

Could someone please help me to extract this color index?

Thank you
Fir





__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Color index in image function

2009-09-05 Thread FMH
Dear All,

I was looking for the color index in image function, such as from 
topo.colors(n) and etc. but still never found it. For instance, from the help 
menu.


###
# Volcano data visualized as matrix. Need to transpose and flip
# matrix horizontally.
image(t(volcano)[ncol(volcano):1,])

# A prettier display of the volcano
x <- 10*(1:nrow(volcano))
y <- 10*(1:ncol(volcano))
image(x, y, volcano, col = terrain.colors(100), axes = FALSE)
contour(x, y, volcano, levels = seq(90, 200, by = 5),
    add = TRUE, col = "peru")
axis(1, at = seq(100, 800, by = 100))
axis(2, at = seq(100, 600, by = 100))
box()
title(main = "Maunga Whau Volcano", font.main = 4)
#

>From the script above, it yields a beautiful  image of volcano with variety of 
>colors but i have to list down the color index that could show the meaning of 
>each color in my thesis. 

Could someone please help me to extract this color index?

Thank you
Fir




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] several questions about R graphic properties

2009-09-05 Thread Антон Морковин

I have a several questions about R graphic properties. 
I use a "barplot2" function for creating plots with error bars. My data include 
species' names in first column, and I need make plots for each species. I know 
how to select species for each plot:

D<-read.table("FD_R.txt", h=T)
Dens<-D[D[,1]=="Sit.eur",]

but I want to make a cycle which will automatically change the species' name 
and save each plot in "jpg" file. How can I do it?

Also, my data include results of two-year work, and I want to make two plots 
for each year one above another in the same box. Is it possible?

And the last question: are there any functions in R which will allow to get 
data from Access? I know about "getfromaccess" function from vegan packcage, 
but it works only with environmental data with very restricted structure. 

I would be very much obliged for your answers.  

A. A. Morkovin, PhD student.

--

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] several questions about R graphic properties

2009-09-05 Thread jim holtman
SOmething like this should work where you 'split' you data frame by
the contents of the first column and then plot the data:

Dens <- split(D, D[,1])
for (i in Dens){  # process each species
jpeg(paste(i[1,1], '.jpg', sep='')  # create file with species name
plot(., main=i[1,1])
dev.off()
}


On Sat, Sep 5, 2009 at 7:52 AM, Антон Морковин wrote:
>
> I have a several questions about R graphic properties.
> I use a "barplot2" function for creating plots with error bars. My data 
> include species' names in first column, and I need make plots for each 
> species. I know how to select species for each plot:
>
> D<-read.table("FD_R.txt", h=T)
> Dens<-D[D[,1]=="Sit.eur",]
>
> but I want to make a cycle which will automatically change the species' name 
> and save each plot in "jpg" file. How can I do it?
>
> Also, my data include results of two-year work, and I want to make two plots 
> for each year one above another in the same box. Is it possible?
>
> And the last question: are there any functions in R which will allow to get 
> data from Access? I know about "getfromaccess" function from vegan packcage, 
> but it works only with environmental data with very restricted structure.
>
> I would be very much obliged for your answers.
>
> A. A. Morkovin, PhD student.
>
> --
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

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


Re: [R] How can I appoint a small part of the whole data

2009-09-05 Thread Yichih Hsieh
Dear all,

I got another problem:

if education have five levels

edu=1
edu=2
edu=3
edu=4
edu=5

If I want to appoint y=edu2~4 in 1990
which programs is correct?
I tried this two programs, they both work, but two results is different.

1.
fig2b<-reldist(y=mu1990$wage[mu1990$edu==2|3|4],..)


2.
fig2b<-reldist(y=mu1990$wage[mu1990$edu%in%2:4],..)

which one is correct?
and why they have different results?


All help high appreciated.


best,
Yichih

2009/9/5 Yichih Hsieh 

>
> Dear Petr,
>
> your suggestion is useful
>
> many thanks for your help !
>
>
> best,
> Yichih
>
> 2009/9/3 Petr PIKAL 
>
> Hi
>>
>> use any of suitable selection ways that are in R.
>>
>> E.g.
>>
>> data[data$gender==1, ]
>>
>> selects only female values
>>
>> data$wage[(data$gender==1)  & (data$race=1)] selects black female wages.
>>
>> and see also ?subset
>>
>> Regards
>> Petr
>>
>> r-help-boun...@r-project.org napsal dne 03.09.2009 10:51:59:
>>
>> > Dear all,
>> >
>> > I have 1980~1990 eleven datas,
>> > every year have three variables,
>> > wage
>> > gender(1=female, 2=male)
>> > race(1=black, 2=white)
>> >
>> > My original commands is:
>> >
>> > fig2b<-reldist(y=mu1990$wage,yo=mu1980$wage,...)
>> >
>> > I have three questions:
>> > 1. If I want to appoint y=women's wage in 1990
>> > yo=women's wage in 1980
>> > 2. If I want to appoint y=women's wage in 1990
>> > yo=men's wage in 1990
>> > 3. If I want to appoint y=black women's wage in 1990
>> > yo=white women's wage in 1990
>> >
>> > How can I modify the commands?
>> >
>> > All help highly appreciated.
>> >
>> > Best,
>> > Yichih
>> >
>> >
>> > --
>> > Yichih Hsieh
>> >
>> > e-mail : yichih.hs...@gmail.com
>> >
>> >[[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>
> --
> Yichih Hsieh
>
> e-mail : yichih.hs...@gmail.com
>



-- 
Yichih Hsieh

e-mail : yichih.hs...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] How can I appoint a small part of the whole data

2009-09-05 Thread baptiste auguie
Hi,

you have two problems in your first scenario,

1- Wrong operator precedence. For example,

> 1 == 2 | 3
[1] TRUE

where 1==2 is tested as FALSE, but 1 is not tested against 3 for equality as
it would be using,

> 1 == 2 | 1 == 3
[1] FALSE

or using %in% 2:3

Instead, R evaluates "FALSE | 3", and

2- it so happens that non-zero integers are treated as TRUE, according to
?"|"

> as.logical(1)
[1] TRUE
> as.logical(0)
[1] FALSE


HTH,

baptiste

2009/9/5 Yichih Hsieh 

> Dear all,
>
> I got another problem:
>
> if education have five levels
>
> edu=1
> edu=2
> edu=3
> edu=4
> edu=5
>
> If I want to appoint y=edu2~4 in 1990
> which programs is correct?
> I tried this two programs, they both work, but two results is different.
>
> 1.
> fig2b<-reldist(y=mu1990$wage[mu1990$edu==2|3|4],..)
>
>
> 2.
> fig2b<-reldist(y=mu1990$wage[mu1990$edu%in%2:4],..)
>
> which one is correct?
> and why they have different results?
>
>
> All help high appreciated.
>
>
> best,
> Yichih
>
> 2009/9/5 Yichih Hsieh 
>
> >
> > Dear Petr,
> >
> > your suggestion is useful
> >
> > many thanks for your help !
> >
> >
> > best,
> > Yichih
> >
> > 2009/9/3 Petr PIKAL 
> >
> > Hi
> >>
> >> use any of suitable selection ways that are in R.
> >>
> >> E.g.
> >>
> >> data[data$gender==1, ]
> >>
> >> selects only female values
> >>
> >> data$wage[(data$gender==1)  & (data$race=1)] selects black female wages.
> >>
> >> and see also ?subset
> >>
> >> Regards
> >> Petr
> >>
> >> r-help-boun...@r-project.org napsal dne 03.09.2009 10:51:59:
> >>
> >> > Dear all,
> >> >
> >> > I have 1980~1990 eleven datas,
> >> > every year have three variables,
> >> > wage
> >> > gender(1=female, 2=male)
> >> > race(1=black, 2=white)
> >> >
> >> > My original commands is:
> >> >
> >> > fig2b<-reldist(y=mu1990$wage,yo=mu1980$wage,...)
> >> >
> >> > I have three questions:
> >> > 1. If I want to appoint y=women's wage in 1990
> >> > yo=women's wage in 1980
> >> > 2. If I want to appoint y=women's wage in 1990
> >> > yo=men's wage in 1990
> >> > 3. If I want to appoint y=black women's wage in 1990
> >> > yo=white women's wage in 1990
> >> >
> >> > How can I modify the commands?
> >> >
> >> > All help highly appreciated.
> >> >
> >> > Best,
> >> > Yichih
> >> >
> >> >
> >> > --
> >> > Yichih Hsieh
> >> >
> >> > e-mail : yichih.hs...@gmail.com
> >> >
> >> >[[alternative HTML version deleted]]
> >> >
> >> > __
> >> > R-help@r-project.org mailing list
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html<
> http://www.r-project.org/posting-guide.html>
> >> > and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
> >
> >
> > --
> > Yichih Hsieh
> >
> > e-mail : yichih.hs...@gmail.com
> >
>
>
>
> --
> Yichih Hsieh
>
> e-mail : yichih.hs...@gmail.com
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

http://newton.ex.ac.uk/research/emag
__

[[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] How can I appoint a small part of the whole data

2009-09-05 Thread Mark Difford

Yichih,

Answer 2 is "correct," because your indexing specification for 1 is wrong.
You also seem to have left out a comma.

##
mu1990$wage[mu1990$edu==2|mu1990$edu==3|mu1990$edu==4, ] ## like this
mu1990$wage[mu1990$edu%in%2:4, ]

You really could have worked this out for yourself by looking at the results
of your subsetting/indexing operation.

Mark.


Yichih Hsieh wrote:
> 
> Dear all,
> 
> I got another problem:
> 
> if education have five levels
> 
> edu=1
> edu=2
> edu=3
> edu=4
> edu=5
> 
> If I want to appoint y=edu2~4 in 1990
> which programs is correct?
> I tried this two programs, they both work, but two results is different.
> 
> 1.
> fig2b<-reldist(y=mu1990$wage[mu1990$edu==2|3|4],..)
> 
> 
> 2.
> fig2b<-reldist(y=mu1990$wage[mu1990$edu%in%2:4],..)
> 
> which one is correct?
> and why they have different results?
> 
> 
> All help high appreciated.
> 
> 
> best,
> Yichih
> 
> 2009/9/5 Yichih Hsieh 
> 
>>
>> Dear Petr,
>>
>> your suggestion is useful
>>
>> many thanks for your help !
>>
>>
>> best,
>> Yichih
>>
>> 2009/9/3 Petr PIKAL 
>>
>> Hi
>>>
>>> use any of suitable selection ways that are in R.
>>>
>>> E.g.
>>>
>>> data[data$gender==1, ]
>>>
>>> selects only female values
>>>
>>> data$wage[(data$gender==1)  & (data$race=1)] selects black female wages.
>>>
>>> and see also ?subset
>>>
>>> Regards
>>> Petr
>>>
>>> r-help-boun...@r-project.org napsal dne 03.09.2009 10:51:59:
>>>
>>> > Dear all,
>>> >
>>> > I have 1980~1990 eleven datas,
>>> > every year have three variables,
>>> > wage
>>> > gender(1=female, 2=male)
>>> > race(1=black, 2=white)
>>> >
>>> > My original commands is:
>>> >
>>> > fig2b<-reldist(y=mu1990$wage,yo=mu1980$wage,...)
>>> >
>>> > I have three questions:
>>> > 1. If I want to appoint y=women's wage in 1990
>>> > yo=women's wage in 1980
>>> > 2. If I want to appoint y=women's wage in 1990
>>> > yo=men's wage in 1990
>>> > 3. If I want to appoint y=black women's wage in 1990
>>> > yo=white women's wage in 1990
>>> >
>>> > How can I modify the commands?
>>> >
>>> > All help highly appreciated.
>>> >
>>> > Best,
>>> > Yichih
>>> >
>>> >
>>> > --
>>> > Yichih Hsieh
>>> >
>>> > e-mail : yichih.hs...@gmail.com
>>> >
>>> >[[alternative HTML version deleted]]
>>> >
>>> > __
>>> > R-help@r-project.org mailing list
>>> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> > PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> > and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> --
>> Yichih Hsieh
>>
>> e-mail : yichih.hs...@gmail.com
>>
> 
> 
> 
> -- 
> Yichih Hsieh
> 
> e-mail : yichih.hs...@gmail.com
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-can-I-appoint-a-small-part-of-the-whole-data-tp25272209p25308714.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] help with functions

2009-09-05 Thread jonas garcia
Thanks Baptiste



On Fri, Sep 4, 2009 at 5:13 PM, baptiste auguie <
baptiste.aug...@googlemail.com> wrote:

> Hi,
>
> I think you've got a problem with environments,
>
> testA<-function(input=1)
>
> {
>
>  dat <- data.frame(A=seq(input,5), B=seq(6,10))
>  vec.names<- c("a", "b")
>  env <- new.env()
>
> for(i in 1:ncol(dat))
>  {
>tab<- dat[,i]-1
>assign(vec.names[i], tab, env=env)
>  }
>  do.call("rbind", lapply(vec.names, get, env=env))
> }
>
> testA()
>
> But more generally, I doubt your construct using assign and get is the most
> natural way to reach your goal in R.
>
> HTH,
>
> baptiste
>
>
> 2009/9/4 jonas garcia 
>
>>  Hi all,
>>
>>
>>
>> I have got 2 function (see bellow) which are simplifications of what I
>> need
>> to do. These functions are precisely the same, except for the last line.
>>
>>
>>
>> My question is, why doesn't function testA work in the same way as
>> function
>> testB.
>>
>> Both functions produce two objects, "a" and "b" that must merged with
>> rbind.
>> The difference is that in testA, I specify the name of the objects while
>> in
>> testA I am stating which objects I want to bind from a character vector.
>>
>>
>>
>> What's more, if I just run the code without a function (example given
>> below
>> as well), they both work...
>>
>> Why is this?
>>
>>
>>
>> Thanks in advance
>>
>>
>>
>> Jonas
>>
>>
>>
>>
>>
>> testA<-function(input)
>>
>> {
>>
>>  dat<- data.frame(A=seq(input,5), B=seq(6,10))
>>
>>  vec.names<- c("a", "b")
>>
>>  for(i in 1:ncol(dat))
>>
>>  {
>>
>>tab<- dat[,i]-1
>>
>>assign(vec.names[i], tab)
>>
>>  }
>>
>>
>>
>>  do.call("rbind", lapply(vec.names, get))
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> testB<-function(input)
>>
>> {
>>
>>  dat<- data.frame(A=seq(input,5), B=seq(6,10))
>>
>>  vec.names<- c("a", "b")
>>
>>  for(i in 1:ncol(dat))
>>
>>  {
>>
>>tab<- dat[,i]-1
>>
>>assign(vec.names[i], tab)
>>
>>  }
>>
>>
>>
>>  rbind(a,b)
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> testA(1)
>>
>> Error in FUN(c("a", "b")[[1L]], ...) : object 'a' not found
>>
>>
>>
>> testB(1)
>>
>>  [,1] [,2] [,3] [,4] [,5]
>>
>> a01234
>>
>> b56789
>>
>>
>>
>>
>>
>>
>>
>>
>> ###
>>
>>
>>
>>
>>
>>
>>
>>  dat<- data.frame(A=seq(1,5), B=seq(6,10))
>>
>>  vec.names<- c("a", "b")
>>
>>  for(i in 1:ncol(dat))
>>
>>  {
>>
>>tab<- dat[,i]-1
>>
>>assign(vec.names[i], tab)
>>
>>  }
>>
>>
>>
>>  do.call("rbind", lapply(vec.names, get))
>>
>> [,1] [,2] [,3] [,4] [,5]
>>
>> [1,]01234
>>
>> [2,]56789
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> dat<- data.frame(A=seq(1,5), B=seq(6,10))
>>
>>  vec.names<- c("a", "b")
>>
>>  for(i in 1:ncol(dat))
>>
>>  {
>>
>>tab<- dat[,i]-1
>>
>>assign(vec.names[i], tab)
>>
>>  }
>>
>>
>>
>>  rbind(a,b)
>>
>>  [,1] [,2] [,3] [,4] [,5]
>>
>> a01234
>>
>> b56789
>>
>>[[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.
>>
>
>
>
> --
> _
>
> Baptiste Auguié
>
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
>
> http://newton.ex.ac.uk/research/emag
> __
>
>

[[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] < 0 x 0 matrix >

2009-09-05 Thread Markku Karhunen




On 04-Sep-09 10:45:27, Markku Karhunen wrote:

True. Should have read ?diag.

However, this provokes a more general question: Is there some way I
can declare some scalar and _all its functions_ as matrices?

For instance, I would like to

A = as.matrix(0.98)
B = function(A)
C = diag(sqrt(B))

so that all scalars are explicitly [1,1] matrices.
BR, Markku


Hmmm, it might be a good idea to explain why you want to do this.
For instance:

  M <- matrix(c(1,2,3,4),nrow=2)
  c <- matrix(2,nrow=1)
  c%*%M
  # Error in c %*% M : non-conformable arguments
  c*M
  # Error in c * M : non-conformable arrays
  c+M
  # Error in c + M : non-conformable arrays

So what would you want to use the [1,1]-matrix scalars for, that
cannot be done just using them as numbers?

Ted.


Broadly speaking, I would like to use the same code for multivariate  
and univariate cases. For instance, I use the inverse Wishart  
densities of MCMCpack. If I take diwish(x) of a scalar x, the  
programme crashes, because diwish() by default checks  
ncol(x)==nrow(x). However, I would like to have an inverse gamma  
density.


Best,
Markku

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Running two R instances at the same time

2009-09-05 Thread Peter Juhasz
Dear R experts,

please excuse me for writing to the mailing list without subscribing.
I have a somewhat urgent problem that relates to R.

I have to process large amounts of data with R - I'm in an
international collaboration and the data processing protocol is fixed,
that is a specific set of R commands has to be used.

I wrote a perl program that manages creation of data subsets from my
database and feeds these subsets to an R process via pipes.

This worked all right, however, I wanted to speed things up by
exploiting the fact that I have a dual-core machine. So I rewrote my
perl driver program to use two threads, each starting its own R
instance, getting data off a queue and feeding it to its R process.

This also worked, except that I noticed something very peculiar: the
processing time was almost exactly the same for both cases. I did some
tests to look at this, and it seems that R needs twice the time to do
the exact same thing if there are two instances of it running.

I don't understand how is this possible. Maybe there is an issue of
thread-safety with the R backend, meaning that the two R *interpreter*
instances are talking to the same backend that's capable of processing
only one thing at a time?

Technical details: OS was Ubuntu 9.04 running on a Core2Dou E7300, and
the R version used was the default one from the Ubuntu repository.

Please see http://www.perlmonks.org/?node_id=792460 for an extended
discussion of the problem, and especially
http://www.perlmonks.org/?node_id=793506 for excerpts of output and
actual code.

Thanks for your answers in advance:
Péter Juhász

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is 'history' recorded in Rscript?

2009-09-05 Thread Peng Yu
Hi,

I got the following error. Does it mean that the files in the save
session will not be saved in history in Rscript?

$ Rscript savehistory.R
> f=tempfile()
> f
[1] "/tmp/RtmpMEGKVq/file327b23c6"
> savehistory(f)
Error in savehistory(file) : no history available to save
Execution halted

Regards,
Peng

On Sat, Sep 5, 2009 at 1:04 AM, David Winsemius wrote:
> You should be looking for .Rhistory
>
> Some OSes make that task difficult. "savehistory" is not the file name but
> rather the name of the function that performs that operation. Try
> savehistory(file="text.Rhistory") and see if the history file is easier to
> find. Should be in your working directory.
>
> Rscript is a program, not a record of the prior session.
>
>
> --
>  David.
>
> On Sep 4, 2009, at 11:03 PM, Peng Yu wrote:
>
>> Hi,
>>
>> I run the following command and try to save the commands that have
>> been run in the script. But it seems that no history is recorded. Is
>> it because that the history is not recorded in Rscript?
>>
>> Regards,
>> Peng
>>
>> $ Rscript savehistory.R
>>>
>>> f=tempfile()
>>> f
>>
>> [1] "/tmp/Rtmp7WBjGG/file327b23c6"
>>>
>>> history()
>>
>> Error in savehistory(file) : no history available to save
>> Calls: history -> savehistory
>> Execution halted
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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
> Heritage Laboratories
> 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] Is 'history' recorded in Rscript?

2009-09-05 Thread David Winsemius
You did not make it clear (to me anyway) what computing environment  
the Rscript command was issued from. I assumed probably incorrectly  
that you were doing this from inside an R session and did not  
understand that Rscript was an external program. If I was wrong about  
that, then you are going to need to provide more details about your  
operating system and how you have set up your R installation.


I also do not know what you mean by a "save session". Did you at some  
time in the past execute a savehistory(file="savehistory,R") command  
at the end of a session and it's now in the directory that Rscript  
look for? That would be the only way that a savehistory.R file would  
exist.


So what OS? What did you do before this failed effort? And what are  
you really trying to do?


Then perhaps someone familiar with your OS can answer.

--
David

.
On Sep 5, 2009, at 10:52 AM, Peng Yu wrote:


Hi,

I got the following error. Does it mean that the files in the save
session will not be saved in history in Rscript?

$ Rscript savehistory.R

f=tempfile()
f

[1] "/tmp/RtmpMEGKVq/file327b23c6"

savehistory(f)

Error in savehistory(file) : no history available to save
Execution halted

Regards,
Peng

On Sat, Sep 5, 2009 at 1:04 AM, David  
Winsemius wrote:

You should be looking for .Rhistory

Some OSes make that task difficult. "savehistory" is not the file  
name but

rather the name of the function that performs that operation. Try
savehistory(file="text.Rhistory") and see if the history file is  
easier to

find. Should be in your working directory.

Rscript is a program, not a record of the prior session.


--
 David.

On Sep 4, 2009, at 11:03 PM, Peng Yu wrote:


Hi,

I run the following command and try to save the commands that have
been run in the script. But it seems that no history is recorded. Is
it because that the history is not recorded in Rscript?

Regards,
Peng

$ Rscript savehistory.R


f=tempfile()
f


[1] "/tmp/Rtmp7WBjGG/file327b23c6"


history()


Error in savehistory(file) : no history available to save
Calls: history -> savehistory
Execution halted


David Winsemius, MD
Heritage Laboratories
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] How to 'apply' on multiple arguments?

2009-09-05 Thread Peng Yu
Hi,

I am wonder if there is a function similar 'apply' but it could accept
multiple arguments?

For example, I have the following matrix.
x=matrix(1:6,nr=2)
y=matrix(1:6,nr=2)

I want to find a function that can be used to compute the linear
regression for each pair of rows in the two matrices?

multiple_apply(x,y,1,function(u,v){lm(u ~ v)}

That is, I wound like something like the above to compute the
following. Can somebody let me know if there is such an command in R?

lm(x[1,]~y[1,])
lm(x[2,]~y[2,])

Regards,
Peng

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Is 'history' recorded in Rscript?

2009-09-05 Thread Peng Yu
Hi,

I run Rscript from the command line (bash). My OS is the following

$ cat  /etc/redhat-release
CentOS release 5 (Final)
$ uname -a
Linux selenium.cluster 2.6.18-53.1.13.el5 #1 SMP Tue Feb 12 13:02:30
EST 2008 x86_64 GNU/Linux
$ dmesg | grep gcc
Linux version 2.6.18-53.1.13.el5 (mockbu...@builder6.centos.org) (gcc
version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Tue Feb 12 13:02:30
EST 2008

I can use savehistory in an R session (that is after the R prompt
'>'). My file 'savehistory.R' only have the following three lines.

f=tempfile()
f
savehistory(f)


I run the command 'Rscript savehistory.R' from the bash command line,
which gave me the error I showed in my previous email. Can somebody
try if he/she receives the save error?

Regards,
Peng

On Sat, Sep 5, 2009 at 10:16 AM, David Winsemius wrote:
> You did not make it clear (to me anyway) what computing environment the
> Rscript command was issued from. I assumed probably incorrectly that you
> were doing this from inside an R session and did not understand that Rscript
> was an external program. If I was wrong about that, then you are going to
> need to provide more details about your operating system and how you have
> set up your R installation.
>
> I also do not know what you mean by a "save session". Did you at some time
> in the past execute a savehistory(file="savehistory,R") command at the end
> of a session and it's now in the directory that Rscript look for? That would
> be the only way that a savehistory.R file would exist.
>
> So what OS? What did you do before this failed effort? And what are you
> really trying to do?
>
> Then perhaps someone familiar with your OS can answer.
>
> --
> David
>
> .
> On Sep 5, 2009, at 10:52 AM, Peng Yu wrote:
>
>> Hi,
>>
>> I got the following error. Does it mean that the files in the save
>> session will not be saved in history in Rscript?
>>
>> $ Rscript savehistory.R
>>>
>>> f=tempfile()
>>> f
>>
>> [1] "/tmp/RtmpMEGKVq/file327b23c6"
>>>
>>> savehistory(f)
>>
>> Error in savehistory(file) : no history available to save
>> Execution halted
>>
>> Regards,
>> Peng
>>
>> On Sat, Sep 5, 2009 at 1:04 AM, David Winsemius
>> wrote:
>>>
>>> You should be looking for .Rhistory
>>>
>>> Some OSes make that task difficult. "savehistory" is not the file name
>>> but
>>> rather the name of the function that performs that operation. Try
>>> savehistory(file="text.Rhistory") and see if the history file is easier
>>> to
>>> find. Should be in your working directory.
>>>
>>> Rscript is a program, not a record of the prior session.
>>>
>>>
>>> --
>>>  David.
>>>
>>> On Sep 4, 2009, at 11:03 PM, Peng Yu wrote:
>>>
 Hi,

 I run the following command and try to save the commands that have
 been run in the script. But it seems that no history is recorded. Is
 it because that the history is not recorded in Rscript?

 Regards,
 Peng

 $ Rscript savehistory.R
>
> f=tempfile()
> f

 [1] "/tmp/Rtmp7WBjGG/file327b23c6"
>
> history()

 Error in savehistory(file) : no history available to save
 Calls: history -> savehistory
 Execution halted
>
> David Winsemius, MD
> Heritage Laboratories
> 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] Running two R instances at the same time

2009-09-05 Thread Jim Holtman
if I look at your output, the single thread is using almost 100% of  
the two cpus (3:49 real, 5:49 user or something close to that).  for  
the two thread case it is close to the same with the user now  
something like 6:15.  I would like to see what the contribution of  
each of the processes are.  put some proc. time calls in the R script  
to see what it is using.


Sent from my iPhone

On Sep 5, 2009, at 7:21, Peter Juhasz  wrote:


Dear R experts,

please excuse me for writing to the mailing list without subscribing.
I have a somewhat urgent problem that relates to R.

I have to process large amounts of data with R - I'm in an
international collaboration and the data processing protocol is fixed,
that is a specific set of R commands has to be used.

I wrote a perl program that manages creation of data subsets from my
database and feeds these subsets to an R process via pipes.

This worked all right, however, I wanted to speed things up by
exploiting the fact that I have a dual-core machine. So I rewrote my
perl driver program to use two threads, each starting its own R
instance, getting data off a queue and feeding it to its R process.

This also worked, except that I noticed something very peculiar: the
processing time was almost exactly the same for both cases. I did some
tests to look at this, and it seems that R needs twice the time to do
the exact same thing if there are two instances of it running.

I don't understand how is this possible. Maybe there is an issue of
thread-safety with the R backend, meaning that the two R *interpreter*
instances are talking to the same backend that's capable of processing
only one thing at a time?

Technical details: OS was Ubuntu 9.04 running on a Core2Dou E7300, and
the R version used was the default one from the Ubuntu repository.

Please see http://www.perlmonks.org/?node_id=792460 for an extended
discussion of the problem, and especially
http://www.perlmonks.org/?node_id=793506 for excerpts of output and
actual code.

Thanks for your answers in advance:
Péter Juhász

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] linear regression between two lists of vectors?

2009-09-05 Thread Peng Yu
Hi,

I am not familiar enough with statistics yet. Please excuse me if my
question is wrong.

In the simplest form of linear regression, the data points are two
list of scalars x_1, ..., x_n and y_1, ..., y_n. I am wondering if
there is a linear regression for two lists of vectors X_1, ..., X_n
and Y_1, ..., Y_n.

'lm' on two vectors, which works. But it seems that 'lm' does not work
on two matrices. Is there a way to do a linear regression on two lists
of vectors?

Regards,
Peng

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Running two R instances at the same time

2009-09-05 Thread Mario Valle
Why instead you don't explore packages 'multicore' or 'snow+showfall 
(using sockets)'?

Ciao!
   mario

Peter Juhasz wrote:

Dear R experts,

please excuse me for writing to the mailing list without subscribing.
I have a somewhat urgent problem that relates to R.

I have to process large amounts of data with R - I'm in an
international collaboration and the data processing protocol is fixed,
that is a specific set of R commands has to be used.

I wrote a perl program that manages creation of data subsets from my
database and feeds these subsets to an R process via pipes.

This worked all right, however, I wanted to speed things up by
exploiting the fact that I have a dual-core machine. So I rewrote my
perl driver program to use two threads, each starting its own R
instance, getting data off a queue and feeding it to its R process.

This also worked, except that I noticed something very peculiar: the
processing time was almost exactly the same for both cases. I did some
tests to look at this, and it seems that R needs twice the time to do
the exact same thing if there are two instances of it running.

I don't understand how is this possible. Maybe there is an issue of
thread-safety with the R backend, meaning that the two R *interpreter*
instances are talking to the same backend that's capable of processing
only one thing at a time?

Technical details: OS was Ubuntu 9.04 running on a Core2Dou E7300, and
the R version used was the default one from the Ubuntu repository.

Please see http://www.perlmonks.org/?node_id=792460 for an extended
discussion of the problem, and especially
http://www.perlmonks.org/?node_id=793506 for excerpts of output and
actual code.

Thanks for your answers in advance:
Péter Juhász

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



--
Ing. Mario Valle
Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)  | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting biological data

2009-09-05 Thread John Casey

Hello all,
 I am new to R but have some experience with MATLAB and am trying to make 
the switch. I generally find the two languages easy to adapt but there are a 
few routine tasks which I would like to run smoother in R and I am having 
trouble finding a help resource. Could someone suggest a guide to filtering, 
selecting, sorting, and processing biological matrix data? Here is a 
rudimentary example of what I'm after [ocean research cruise- 
data.frame<-example]:
 
Cruise, dec yr, station, cast, depth, data1
1, 2007.65, 9, 29, 1, 105.04
1, 2007.65, 9, 29, 10, 104.91
1, 2007.65, 9, 29, 20, 101.43
1, 2007.65, 9, 29, 50, 100.68
1, 2007.65, 9, 29, 100, 100.09
1, 2007.69, 11, 33, 1, 107.32
1, 2007.69, 11, 33, 10, 105.94
1, 2007.69, 11, 33, 20, 102.19
1, 2007.69, 11, 33, 50, 101.27
1, 2007.69, 11, 33, 100, 100.15

Let's say I would like to select data1 from cast 33 at 1, 20, and 100m depth... 
how would I go about this?

Thanks in advance for helping out a greenhorn!
John


_

 Facebook.

:ON:WL:en-US:SI_SB_facebook:082009
[[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] How to 'apply' on multiple arguments?

2009-09-05 Thread Henrique Dallazuanna
Yes, see mapply.

On Sat, Sep 5, 2009 at 12:18 PM, Peng Yu  wrote:

> Hi,
>
> I am wonder if there is a function similar 'apply' but it could accept
> multiple arguments?
>
> For example, I have the following matrix.
> x=matrix(1:6,nr=2)
> y=matrix(1:6,nr=2)
>
> I want to find a function that can be used to compute the linear
> regression for each pair of rows in the two matrices?
>
> multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
>
> That is, I wound like something like the above to compute the
> following. Can somebody let me know if there is such an command in R?
>
> lm(x[1,]~y[1,])
> lm(x[2,]~y[2,])
>
> Regards,
> Peng
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


Re: [R] Selecting biological data

2009-09-05 Thread Jim Holtman

subset(data1,cast==33&(depth %in% c(1,20,100))

Sent from my iPhone

On Sep 5, 2009, at 11:58, John Casey  wrote:



Hello all,
I am new to R but have some experience with MATLAB and am trying  
to make the switch. I generally find the two languages easy to adapt  
but there are a few routine tasks which I would like to run smoother  
in R and I am having trouble finding a help resource. Could someone  
suggest a guide to filtering, selecting, sorting, and processing  
biological matrix data? Here is a rudimentary example of what I'm  
after [ocean research cruise- data.frame<-example]:


Cruise, dec yr, station, cast, depth, data1
1, 2007.65, 9, 29, 1, 105.04
1, 2007.65, 9, 29, 10, 104.91
1, 2007.65, 9, 29, 20, 101.43
1, 2007.65, 9, 29, 50, 100.68
1, 2007.65, 9, 29, 100, 100.09
1, 2007.69, 11, 33, 1, 107.32
1, 2007.69, 11, 33, 10, 105.94
1, 2007.69, 11, 33, 20, 102.19
1, 2007.69, 11, 33, 50, 101.27
1, 2007.69, 11, 33, 100, 100.15

Let's say I would like to select data1 from cast 33 at 1, 20, and  
100m depth... how would I go about this?


Thanks in advance for helping out a greenhorn!
John


_

Facebook.

:ON:WL:en-US:SI_SB_facebook:082009
   [[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] Selecting biological data

2009-09-05 Thread David Winsemius


On Sep 5, 2009, at 11:58 AM, John Casey wrote:



Hello all,
I am new to R but have some experience with MATLAB and am trying  
to make the switch. I generally find the two languages easy to adapt  
but there are a few routine tasks which I would like to run smoother  
in R and I am having trouble finding a help resource. Could someone  
suggest a guide to filtering, selecting, sorting, and processing  
biological matrix data? Here is a rudimentary example of what I'm  
after [ocean research cruise- data.frame<-example]:


Cruise, dec yr, station, cast, depth, data1
1, 2007.65, 9, 29, 1, 105.04
1, 2007.65, 9, 29, 10, 104.91
1, 2007.65, 9, 29, 20, 101.43
1, 2007.65, 9, 29, 50, 100.68
1, 2007.65, 9, 29, 100, 100.09
1, 2007.69, 11, 33, 1, 107.32
1, 2007.69, 11, 33, 10, 105.94
1, 2007.69, 11, 33, 20, 102.19
1, 2007.69, 11, 33, 50, 101.27
1, 2007.69, 11, 33, 100, 100.15

Let's say I would like to select data1 from cast 33 at 1, 20, and  
100m depth... how would I go about this?


?subset

subset(df1, cast==33 & depth %in% c(1,20,100) )

... or since your specification was vague;

subset(df1, cast==33 & depth==1 )
subset(df1, cast==33 & depth==20 )
subset(df1, cast==33 & depth==100 )

Also:
?"["
# the first column specification can be a logical vector, as in  
df1[df1$col1 == 20, ] and will return subsets. But subset function is  
nicer in that you don't have precede each column name by the dataframe  
name.


And of course:




Thanks in advance for helping out a greenhorn!
John


_

Facebook.

:ON:WL:en-US:SI_SB_facebook:082009
[[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
Heritage Laboratories
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] How to 'apply' on multiple arguments?

2009-09-05 Thread Peng Yu
Hi,

I tried the following code. For example, I want to add the
corresponding rows of x and y. I expect that the result be a matrix of
the same size. But the actual result is different from what I expect.
Would you please let me know what the correct command should be?

Regards,
Peng

> x=matrix(1:6,nr=2)
> y=matrix(1:6,nr=2)
> mapply(function(u,v){u + v},x,y)
[1]  2  4  6  8 10 12


On Sat, Sep 5, 2009 at 10:59 AM, Henrique Dallazuanna wrote:
> Yes, see mapply.
>
> On Sat, Sep 5, 2009 at 12:18 PM, Peng Yu  wrote:
>>
>> Hi,
>>
>> I am wonder if there is a function similar 'apply' but it could accept
>> multiple arguments?
>>
>> For example, I have the following matrix.
>> x=matrix(1:6,nr=2)
>> y=matrix(1:6,nr=2)
>>
>> I want to find a function that can be used to compute the linear
>> regression for each pair of rows in the two matrices?
>>
>> multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
>>
>> That is, I wound like something like the above to compute the
>> following. Can somebody let me know if there is such an command in R?
>>
>> lm(x[1,]~y[1,])
>> lm(x[2,]~y[2,])
>>
>> Regards,
>> Peng
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Convert dataframe to array of records

2009-09-05 Thread Jeroen Ooms

I would like to convert a dataframe to an array of lists, one for every
record. A natural choide is apply as.list to the rows. However, as it seems,
as.list() automatically converts all list elements to the same datatype. Eg:

myData <- data.frame(a="foo",b=as.logical(rbinom(10,1,.5)));
apply(myData,1,as.list);

In this output, all boolean values have been converted to character strings.
I don't understand why this happens; a list does not require that every
element is of the same datatype. Is there an easy way (ie avoid for-loops
etc) to convert the dataframe to an array of records, while keeping the
datatypes for every field? 

-
Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University 

Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
current projects.





 
-- 
View this message in context: 
http://www.nabble.com/Convert-dataframe-to-array-of-records-tp25310023p25310023.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] Selecting biological data

2009-09-05 Thread David Winsemius


On Sep 5, 2009, at 12:13 PM, David Winsemius wrote:



On Sep 5, 2009, at 11:58 AM, John Casey wrote:



Hello all,
   I am new to R but have some experience with MATLAB and am trying  
to make the switch.

snipped specifics



And of course:


Sorry: got distracted and forgot to append the intended links:

http://germain.its.maine.edu/~hiebeler/comp/matlabR.pdf

http://cran.r-project.org/doc/contrib/R-and-octave.txt






Thanks in advance for helping out a greenhorn!
John


_

Facebook.

:ON:WL:en-US:SI_SB_facebook:082009
[[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
Heritage Laboratories
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.


David Winsemius, MD
Heritage Laboratories
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] How to 'apply' on multiple arguments?

2009-09-05 Thread Jorge Ivan Velez
Hi Peng,
Here is a suugestion using lapply():

res <- lapply(1:2, function(i) lm( x[i, ] ~ y[i, ]) )
names(res) <- c('row1','row2')
res

# The summaries for each regression
lapply(res, summary)

# for the coefficients only
lapply(res, coef)

# ANOVAs
lapply(res, anova)

HTH,
Jorge


On Sat, Sep 5, 2009 at 11:18 AM, Peng Yu  wrote:

> Hi,
>
> I am wonder if there is a function similar 'apply' but it could accept
> multiple arguments?
>
> For example, I have the following matrix.
> x=matrix(1:6,nr=2)
> y=matrix(1:6,nr=2)
>
> I want to find a function that can be used to compute the linear
> regression for each pair of rows in the two matrices?
>
> multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
>
> That is, I wound like something like the above to compute the
> following. Can somebody let me know if there is such an command in R?
>
> lm(x[1,]~y[1,])
> lm(x[2,]~y[2,])
>
> Regards,
> Peng
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] How to 'apply' on multiple arguments?

2009-09-05 Thread Henrique Dallazuanna
HI,

Try this:
mapply(`+`, as.data.frame(x), as.data.frame(y))

You are using matrices, which are vectors with dim attributes, then you need
convert to data.frame

On Sat, Sep 5, 2009 at 1:16 PM, Peng Yu  wrote:

> Hi,
>
> I tried the following code. For example, I want to add the
> corresponding rows of x and y. I expect that the result be a matrix of
> the same size. But the actual result is different from what I expect.
> Would you please let me know what the correct command should be?
>
> Regards,
> Peng
>
> > x=matrix(1:6,nr=2)
> > y=matrix(1:6,nr=2)
> > mapply(function(u,v){u + v},x,y)
> [1]  2  4  6  8 10 12
>
>
> On Sat, Sep 5, 2009 at 10:59 AM, Henrique Dallazuanna
> wrote:
> > Yes, see mapply.
> >
> > On Sat, Sep 5, 2009 at 12:18 PM, Peng Yu  wrote:
> >>
> >> Hi,
> >>
> >> I am wonder if there is a function similar 'apply' but it could accept
> >> multiple arguments?
> >>
> >> For example, I have the following matrix.
> >> x=matrix(1:6,nr=2)
> >> y=matrix(1:6,nr=2)
> >>
> >> I want to find a function that can be used to compute the linear
> >> regression for each pair of rows in the two matrices?
> >>
> >> multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
> >>
> >> That is, I wound like something like the above to compute the
> >> following. Can somebody let me know if there is such an command in R?
> >>
> >> lm(x[1,]~y[1,])
> >> lm(x[2,]~y[2,])
> >>
> >> Regards,
> >> Peng
> >>
> >> __
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> >
> >
> > --
> > Henrique Dallazuanna
> > Curitiba-Paraná-Brasil
> > 25° 25' 40" S 49° 16' 22" O
> >
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

[[alternative HTML version deleted]]

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


Re: [R] Calling R from a Perl script: much slower?

2009-09-05 Thread Jim Holtman
you might also look at the output of 'ps' to see how much time each  
process is using.  also instrument your R script to collect the cpu  
time.


Sent from my iPhone

On Sep 4, 2009, at 11:34, j.delashe...@ed.ac.uk wrote:



Ah! sorted!

it was NOT running the same code.

We're making a GUI using Perl (Tcl/Tkx) to facilitate a number of  
analyses in our lab to other people who don't necessarily want to  
know about R (their loss ;-)


I provided the R code to my colleague and he assured me he used it  
without changes... but when I've looked into it, there were a number  
of changes... (?) I restored the code to what I knew to work and  
from the Tcl/Tkx GUI it's *almost* as fast as when I run it from a  
clean session from the R console. So that was the problem.


In case I'm still not doing things teh best way, we're invoking R  
from Perl like this:


invoking the script from Perl:
@output = qx($R.exe --vanilla --args $list of arguments...)

should I use Rterm.exe or Rcmd.exe instead of R.exe?

Jose




Quoting jim holtman :


What operating system are you running under?  You should take a look
at the R process and see how much time it is using to see if there is
a difference in the CPU time.  Are you paging?  Exactly how are you
invoking the R script?  Why are you using the GUI instead of Rterm?
You might try to run Rprof on the code to see if there are
differences.  Are you sure you are running exactly the same data in
both cases?

On Thu, Sep 3, 2009 at 11:42 AM,  wrote:


Hello list,

I use R for microarray analysis.
One procedure I use takes a large matrix, and loops through it  
looking for
specific rows, does an operation with them, and outputs a result  
(single

row) as a row of another matrix. The loop goes on about 25000 times.

When I run the loop directly from the R console itself, it takes  
about 3

minutes in my computer. I'm ok with that.

Now, when that same code is ran from within a GUI we created using  
Perl

(Tcl/Tkx) it's taking 25-30 minutes to run.

Within the R code I inserted a line so that it writes a little  
file every
1000th iteration of the loop, so that I can follow the progress. I  
don't

understand why it takes 10x longer when ran from Perl.

I am not new to R, but I am new to using it within Perl or any other
language. Is there a way to improve performance? What is the  
reason for the

slower speed?

I'll happily provide the code if somebody wants it.

thank you.

Jose

--
Dr. Jose I. de las Heras  Email: j.delashe...@ed.ac.uk
The Wellcome Trust Centre for Cell BiologyPhone: +44 (0)131 6513374
Institute for Cell & Molecular BiologyFax:   +44 (0)131 6507360
Swann Building, Mayfield Road
University of Edinburgh
Edinburgh EH9 3JR
UK
*
NEW EMAIL from July'09: nach.mcn...@gmail.com
*

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?






--
Dr. Jose I. de las Heras  Email: j.delashe...@ed.ac.uk
The Wellcome Trust Centre for Cell BiologyPhone: +44 (0)131  
6513374
Institute for Cell & Molecular BiologyFax:   +44 (0)131  
6507360

Swann Building, Mayfield Road
University of Edinburgh
Edinburgh EH9 3JR
UK
*
NEW EMAIL from July'09: nach.mcn...@gmail.com
*

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Convert dataframe to array of records

2009-09-05 Thread William Dunlap
> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Jeroen Ooms
> Sent: Saturday, September 05, 2009 9:20 AM
> To: r-help@r-project.org
> Subject: [R] Convert dataframe to array of records
> 
> 
> I would like to convert a dataframe to an array of lists, one 
> for every
> record. A natural choide is apply as.list to the rows. 
> However, as it seems,
> as.list() automatically converts all list elements to the 
> same datatype.

No, apply itself converts the whole data.frame to a matrix,
forcing the columns to one data type.  I think that apply()
is rarely a good tool for working with data.frames.

You will have to do something like
rowsOfDataFrame <- function(dataframe)
lapply(seq_len(nrow(dataframe)), function(i)dataframe[i,])
or perhaps as.list(dataframe[i,]) if you really want to get rid
of the data.frame-ness.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com  

> Eg:
> 
> myData <- data.frame(a="foo",b=as.logical(rbinom(10,1,.5)));
> apply(myData,1,as.list);
> 
> In this output, all boolean values have been converted to 
> character strings.
> I don't understand why this happens; a list does not require 
> that every
> element is of the same datatype. Is there an easy way (ie 
> avoid for-loops
> etc) to convert the dataframe to an array of records, while 
> keeping the
> datatypes for every field? 
> 
> -
> Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht 
> University 
> 
> Visit  http://www.jeroenooms.com www.jeroenooms.com  to 
> explore some of my
> current projects.
> 
> 
> 
> 
> 
>  
> -- 
> View this message in context: 
> http://www.nabble.com/Convert-dataframe-to-array-of-records-tp
25310023p25310023.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

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


Re: [R] extract and replace columns of matrices stored in a list

2009-09-05 Thread Henrique Dallazuanna
Try this:

my.array <- replicate(10, data.frame(matrix(sample(9), 3)), simplify =
FALSE)

#2
lapply(my.array, replace, list = 3, values = newThirdColumn)


The solution was for matrices, the above works with data.frames.

On Thu, Sep 3, 2009 at 5:03 PM, Carlos Hernandez wrote:

>
> On Thu, Sep 3, 2009 at 4:34 PM, Henrique Dallazuanna wrote:
>
>> Try this:
>>
>> #1
>> lapply(my.array, '[', , 3)
>>
>>
> this works! thank you a lot!
>
>
>> #2
>> newThirdColumn <- sample(3)
>> lapply(my.array, replace, list = 7:9, values = newThirdColumn)
>>
>>
> i did not understand this last line, so far i couldn't make it work.
>
>  would it be easier to replace the values (the third column of each matrix
> in my.array) using an array like in #1?
>
> thank you for your reply!
>
>
>> On Thu, Sep 3, 2009 at 11:16 AM, Carlos Hernandez 
>> wrote:
>>
>>> Dear All,
>>> I created a list (of length Z) in the following way:
>>>
>>> my.array <- vector("list", Z)
>>>
>>> then i assigned a matrix (of T rows by N columns) in each of the elements
>>> of
>>> the list my.array in the following way:
>>>
>>> my.array[[i]] <- matrix.data   ##( matrix.data has dimensions TxN, and i
>>> repeated this command for i from 1 to Z, the matrix.data contains only
>>> numeric data)
>>>
>>> and
>>> 1. i would like to extract all the third columns of each of the Z
>>> matrices
>>> stored in my.array (such that i get a new list only with the 3rd columns
>>> of
>>> each matrix in the elements of a new list)
>>>
>>> 2. i would like to know how could i replace all the 3rd columns of each
>>> matrix in my.array if i have a second matrix (size ZxT) with these
>>> columns.
>>>
>>> is there a simple way to do these tasks? i appreciate any hints or
>>> advice.
>>>
>>> Carlos
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>>
>> --
>> Henrique Dallazuanna
>> Curitiba-Paraná-Brasil
>> 25° 25' 40" S 49° 16' 22" O
>>
>
>


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

[[alternative HTML version deleted]]

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


Re: [R] Is 'history' recorded in Rscript?

2009-09-05 Thread Duncan Murdoch

On 05/09/2009 2:21 PM, David Winsemius wrote:
I get the same error in a bash session on a Mac. My assumption at this  
point is is that the authors of Rscript decided that you should  
already know what is in the input file and so left out that feature of  
the console program. Mavbe if you explained why you wanted what would  
generally be a straight copy of the input file, someone can offer a  
work-around strategy.


In interactive use the GUIs (or Rterm) have their own mechanisms to 
maintain history.  As the man page for savehistory says, in batch use 
there is no history maintained.


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] Is 'history' recorded in Rscript?

2009-09-05 Thread David Winsemius
I get the same error in a bash session on a Mac. My assumption at this  
point is is that the authors of Rscript decided that you should  
already know what is in the input file and so left out that feature of  
the console program. Mavbe if you explained why you wanted what would  
generally be a straight copy of the input file, someone can offer a  
work-around strategy.


--
David
On Sep 5, 2009, at 11:26 AM, Peng Yu wrote:


Hi,

I run Rscript from the command line (bash). My OS is the following

$ cat  /etc/redhat-release
CentOS release 5 (Final)
$ uname -a
Linux selenium.cluster 2.6.18-53.1.13.el5 #1 SMP Tue Feb 12 13:02:30
EST 2008 x86_64 GNU/Linux
$ dmesg | grep gcc
Linux version 2.6.18-53.1.13.el5 (mockbu...@builder6.centos.org) (gcc
version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Tue Feb 12 13:02:30
EST 2008

I can use savehistory in an R session (that is after the R prompt
'>'). My file 'savehistory.R' only have the following three lines.

f=tempfile()
f
savehistory(f)


I run the command 'Rscript savehistory.R' from the bash command line,
which gave me the error I showed in my previous email. Can somebody
try if he/she receives the save error?

Regards,
Peng

On Sat, Sep 5, 2009 at 10:16 AM, David Winsemius> wrote:
You did not make it clear (to me anyway) what computing environment  
the
Rscript command was issued from. I assumed probably incorrectly  
that you
were doing this from inside an R session and did not understand  
that Rscript
was an external program. If I was wrong about that, then you are  
going to
need to provide more details about your operating system and how  
you have

set up your R installation.

I also do not know what you mean by a "save session". Did you at  
some time
in the past execute a savehistory(file="savehistory,R") command at  
the end
of a session and it's now in the directory that Rscript look for?  
That would

be the only way that a savehistory.R file would exist.

So what OS? What did you do before this failed effort? And what are  
you

really trying to do?

Then perhaps someone familiar with your OS can answer.

--
David

.
On Sep 5, 2009, at 10:52 AM, Peng Yu wrote:


Hi,

I got the following error. Does it mean that the files in the save
session will not be saved in history in Rscript?

$ Rscript savehistory.R


f=tempfile()
f


[1] "/tmp/RtmpMEGKVq/file327b23c6"


savehistory(f)


Error in savehistory(file) : no history available to save
Execution halted

Regards,
Peng

On Sat, Sep 5, 2009 at 1:04 AM, David Winsemius>

wrote:


You should be looking for .Rhistory

Some OSes make that task difficult. "savehistory" is not the file  
name

but
rather the name of the function that performs that operation. Try
savehistory(file="text.Rhistory") and see if the history file is  
easier

to
find. Should be in your working directory.

Rscript is a program, not a record of the prior session.


--
 David.

On Sep 4, 2009, at 11:03 PM, Peng Yu wrote:


Hi,

I run the following command and try to save the commands that have
been run in the script. But it seems that no history is  
recorded. Is

it because that the history is not recorded in Rscript?

Regards,
Peng

$ Rscript savehistory.R


f=tempfile()
f


[1] "/tmp/Rtmp7WBjGG/file327b23c6"


history()


Error in savehistory(file) : no history available to save
Calls: history -> savehistory
Execution halted


David Winsemius, MD
Heritage Laboratories
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.


David Winsemius, MD
Heritage Laboratories
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] help with functions

2009-09-05 Thread jim holtman
Try this variation; might have something to do with scope:

testA<-function(input)
{
 dat<- data.frame(A=seq(input,5), B=seq(6,10))
 vec.names<- c("a", "b")
 for(i in 1:ncol(dat))
 {
   tab<- dat[,i]-1
   assign(vec.names[i], tab)
 }
 do.call("rbind", lapply(vec.names, function(x) get(x)))
}

Just changed the way 'get' was done in the lapply

On Fri, Sep 4, 2009 at 10:00 AM, jonas
garcia wrote:
> Hi all,
>
>
>
> I have got 2 function (see bellow) which are simplifications of what I need
> to do. These functions are precisely the same, except for the last line.
>
>
>
> My question is, why doesn't function testA work in the same way as function
> testB.
>
> Both functions produce two objects, "a" and "b" that must merged with rbind.
> The difference is that in testA, I specify the name of the objects while in
> testA I am stating which objects I want to bind from a character vector.
>
>
>
> What's more, if I just run the code without a function (example given below
> as well), they both work...
>
> Why is this?
>
>
>
> Thanks in advance
>
>
>
> Jonas
>
>
>
>
>
> testA<-function(input)
>
> {
>
>      dat<- data.frame(A=seq(input,5), B=seq(6,10))
>
>      vec.names<- c("a", "b")
>
>      for(i in 1:ncol(dat))
>
>      {
>
>            tab<- dat[,i]-1
>
>            assign(vec.names[i], tab)
>
>      }
>
>
>
>      do.call("rbind", lapply(vec.names, get))
>
> }
>
>
>
>
>
>
>
> testB<-function(input)
>
> {
>
>      dat<- data.frame(A=seq(input,5), B=seq(6,10))
>
>      vec.names<- c("a", "b")
>
>      for(i in 1:ncol(dat))
>
>      {
>
>            tab<- dat[,i]-1
>
>            assign(vec.names[i], tab)
>
>      }
>
>
>
>      rbind(a,b)
>
> }
>
>
>
>
>
>
>
> testA(1)
>
> Error in FUN(c("a", "b")[[1L]], ...) : object 'a' not found
>
>
>
> testB(1)
>
>  [,1] [,2] [,3] [,4] [,5]
>
> a    0    1    2    3    4
>
> b    5    6    7    8    9
>
>
>
>
>
>
>
> ###
>
>
>
>
>
>
>
>      dat<- data.frame(A=seq(1,5), B=seq(6,10))
>
>      vec.names<- c("a", "b")
>
>      for(i in 1:ncol(dat))
>
>      {
>
>            tab<- dat[,i]-1
>
>            assign(vec.names[i], tab)
>
>      }
>
>
>
>      do.call("rbind", lapply(vec.names, get))
>
>     [,1] [,2] [,3] [,4] [,5]
>
> [1,]    0    1    2    3    4
>
> [2,]    5    6    7    8    9
>
>
>
>
>
>
>
>
>
> dat<- data.frame(A=seq(1,5), B=seq(6,10))
>
>      vec.names<- c("a", "b")
>
>      for(i in 1:ncol(dat))
>
>      {
>
>            tab<- dat[,i]-1
>
>            assign(vec.names[i], tab)
>
>      }
>
>
>
>      rbind(a,b)
>
>  [,1] [,2] [,3] [,4] [,5]
>
> a    0    1    2    3    4
>
> b    5    6    7    8    9
>
>        [[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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] save image from R to database server in binary format

2009-09-05 Thread Harsh
Hello,
I would appreciate help regarding converting an image (jpeg, bmp) in R and
saving it to a postgresql database server.
Does the writeBin function provide any support for image to binary
conversion?
Once converted, how can I use the packages "DBI" and "RPostgreSQL" to send
such data into the server.

I am running R 2.9.0 on WinXP and running postgresql 8.3

Thank you
Harsh Singhal

[[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] Anova over a list of models

2009-09-05 Thread Jeroen Ooms

I have a list object, in which I have stored n lme4-models. For example:

library(lme4);
myModels <- list();
myModels[1] <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
myModels[2] <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject),
sleepstudy)

Now I would like to perform an anova over all models in the list. However,
the anova function requires that every model is inserted as a seperate
argument, i.e. anova(model1,model2). I run into two problems:
1) anova(myModels[1],myModels[2]) returns an error.
2) if n, the number of models, is unknown, how do I add all models as a
seperate argument? 



-
Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University 

Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
current projects.





 
-- 
View this message in context: 
http://www.nabble.com/Anova-over-a-list-of-models-tp25311985p25311985.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] < 0 x 0 matrix >

2009-09-05 Thread Ted Harding
On 05-Sep-09 10:00:26, Markku Karhunen wrote:
>> On 04-Sep-09 10:45:27, Markku Karhunen wrote:
>>> True. Should have read ?diag.
>>>
>>> However, this provokes a more general question: Is there some way I
>>> can declare some scalar and _all its functions_ as matrices?
>>>
>>> For instance, I would like to
>>>
>>> A = as.matrix(0.98)
>>> B = function(A)
>>> C = diag(sqrt(B))
>>>
>>> so that all scalars are explicitly [1,1] matrices.
>>> BR, Markku
>>
>> Hmmm, it might be a good idea to explain why you want to do this.
>> For instance:
>>
>>   M <- matrix(c(1,2,3,4),nrow=2)
>>   c <- matrix(2,nrow=1)
>>   c%*%M
>>   # Error in c %*% M : non-conformable arguments
>>   c*M
>>   # Error in c * M : non-conformable arrays
>>   c+M
>>   # Error in c + M : non-conformable arrays
>>
>> So what would you want to use the [1,1]-matrix scalars for, that
>> cannot be done just using them as numbers?
>>
>> Ted.
> 
> Broadly speaking, I would like to use the same code for multivariate  
> and univariate cases. For instance, I use the inverse Wishart  
> densities of MCMCpack. If I take diwish(x) of a scalar x, the  
> programme crashes, because diwish() by default checks  
> ncol(x)==nrow(x). However, I would like to have an inverse gamma  
> density.
> 
> Best,
> Markku

I see. In such a case, it might be worth wrapping diwish() inside
a function of your own, which tests for 'x' being a scalar and,
if it is, converting it to a 1x1 matrix within the function.
For example:

  diWish <- function(x){
if( all.equal(dim(x),c(1,1)) ) {X <- x} else
if( (is.vector(x))&(length(x)==1) ) X <- as.matrix(x)
diwish(X)
  }

(This may not be optimal, but it gives the idea).
Hoping this helps,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 05-Sep-09   Time: 21:26:29
-- XFMail --

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


Re: [R] Anova over a list of models

2009-09-05 Thread Henrique Dallazuanna
Try this:

1)
anova(myModels[[1]],myModels[[2]])

2)
do.call(anova, myModels)

On Sat, Sep 5, 2009 at 5:18 PM, Jeroen Ooms  wrote:

>
> I have a list object, in which I have stored n lme4-models. For example:
>
> library(lme4);
> myModels <- list();
> myModels[1] <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
> myModels[2] <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject),
> sleepstudy)
>
> Now I would like to perform an anova over all models in the list. However,
> the anova function requires that every model is inserted as a seperate
> argument, i.e. anova(model1,model2). I run into two problems:
> 1) anova(myModels[1],myModels[2]) returns an error.
> 2) if n, the number of models, is unknown, how do I add all models as a
> seperate argument?
>
>
>
> -
> Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University
>
> Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
> current projects.
>
>
>
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Anova-over-a-list-of-models-tp25311985p25311985.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.
>



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

[[alternative HTML version deleted]]

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


Re: [R] Anova over a list of models

2009-09-05 Thread Jeroen Ooms
2009/9/5 Henrique Dallazuanna 
>
> Try this:
> anova(myModels[[1]],myModels[[2]])
>
> do.call(anova, myModels)

Does this work for you? Both functions are failing here:

> anova(myModels[[1]],myModels[[2]])
Error in names(mods) <- sapply(as.list(mCall)[c(FALSE, TRUE, modp)],
as.character) :
  'names' attribute [6] must be the same length as the vector [2]
> do.call(anova, myModels)
Error in as.character.default(X[[1L]], ...) :
  no method for coercing this S4 class to a vector

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


Re: [R] How to or or and all the values in a logical vector?

2009-09-05 Thread Chi Yau

Try this:

# Use cummin for 'and'
>  x <- c(TRUE, TRUE, FALSE, TRUE)
> cummin(x) == TRUE# the last element below is the result you want
[1]  TRUE  TRUE FALSE FALSE


# Use cummax for 'or'
> y <- c(FALSE, FALSE, TRUE, FALSE)
> cummax(y) == TRUE# the last element below is the result you want
[1] FALSE FALSE  TRUE  TRUE




David Winsemius wrote:
> 
> 
> On Sep 4, 2009, at 10:37 PM, Peng Yu wrote:
> 
>> Hi,
>>
>> Suppose I have a logical vector x, I want to compute the 'and'
> 
> ?all
> 
>> and
>> 'or'
> 
> ?any
> 
>> of all its element (the result should be a single value TRUE or
>> FALSE). I have read the R-intro.pdf logical vector section, but I
>> don't find the answer.
> 
> I couldn't find them either.
> 
>> Can somebody let me know how to do it?
>>
>>> x= rep(TRUE, 3)
>>
>> Regards,
>> Peng
> 
> -- 
> 
> David Winsemius, MD
> Heritage Laboratories
> 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.
> 
> 


-
Chi Yau
http://r-tutor.com http://r-tutor.com 


-- 
View this message in context: 
http://www.nabble.com/How-to-or-or-and-all-the-values-in-a-logical-vector--tp25304562p25312249.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] Easy way to get top 2 items from vector

2009-09-05 Thread jim holtman
Tyr this:

> system.time(sort(x, partial=c(99,100)))
   user  system elapsed
   0.120.000.14


On Fri, Sep 4, 2009 at 3:53 AM, ONKELINX,
Thierry wrote:
> Using tail() for the selection is more elegant and slightly faster.
>
>> N<- 100
>> x <- runif(N)
>> system.time(x[order(x)[c(N-1,N)]])
>   user  system elapsed
>   1.08    0.01    1.10
>> system.time(sort(x)[c(N-1,N)])
>   user  system elapsed
>   0.36    0.00    0.35
>> system.time(tail(sort(x), 2))
>   user  system elapsed
>   0.33    0.00    0.33
>
>
> HTH,
>
> Thierry
>
> 
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
> Forest
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, 
> methodology and quality assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium
> tel. + 32 54/436 185
> thierry.onkel...@inbo.be
> www.inbo.be
>
> To call in the statistician after the experiment is done may be no more than 
> asking him to perform a post-mortem examination: he may be able to say what 
> the experiment died of.
> ~ Sir Ronald Aylmer Fisher
>
> The plural of anecdote is not data.
> ~ Roger Brinner
>
> The combination of some data and an aching desire for an answer does not 
> ensure that a reasonable answer can be extracted from a given body of data.
> ~ John Tukey
>
> -Oorspronkelijk bericht-
> Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
> Namens andrew
> Verzonden: vrijdag 4 september 2009 4:24
> Aan: r-help@r-project.org
> Onderwerp: Re: [R] Easy way to get top 2 items from vector
>
> it is speedier to use sort than a combination of [] and order:
>
> N<- 100
> x <- runif(N)
>> system.time(x[order(x)[c(N-1,N)]])
>   user  system elapsed
>   1.03    0.00    1.03
>> system.time(sort(x)[c(N-1,N)])
>   user  system elapsed
>   0.28    0.00    0.28
>
>
>
> On Sep 4, 11:17 am, Noah Silverman  wrote:
>> Phil,
>>
>> That's perfect.  (For my application, I've never seen a tie.  While
>> possible, the likelihood is almost none.)
>>
>> Thanks!
>>
>> --
>> Noah
>>
>> On 9/3/09 4:29 PM, Phil Spector wrote:
>>
>>
>>
>> > Noah -
>> >    max(x[-which.max(x)]  will give you the second largest value, but
>> > it doesn't handle ties.
>> >    x[order(x,decreasing=TRUE)[n]]  will give you the nth largest
>> > value, with the same caveat regarding ties.  For example,
>> > x[order(x,decreasing=TRUE)[1:3]] will give you the three largest
>> > values.
>>
>> >                     - Phil Spector
>> >                      Statistical Computing Facility
>> >                      Department of Statistics
>> >                      UC Berkeley
>> >                      spec...@stat.berkeley.edu
>>
>> > On Thu, 3 Sep 2009, Noah Silverman wrote:
>>
>> >> Hi,
>>
>> >> I use the max function often to find the top value from a matrix or
>> >> column of a data.frame.
>>
>> >> Now I'm looking to find the top 2 (or three) values from my data.
>>
>> >> I know that I could sort the list and then access the first two
>> >> items, but that seems like the "long way".  Is there some way to
>> >> access "max_2" or similar?
>>
>> >> Thanks!
>>
>> >> --
>> >> Noah
>>
>> >> __
>> >> r-h...@r-project.org mailing list
>> >>https://stat.ethz.ch/mailman/listinfo/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-h...@r-project.org mailing
>> listhttps://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting
>> guidehttp://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.
>
> Druk dit bericht a.u.b. niet onnodig af.
> Please do not print this message unnecessarily.
>
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
> en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd 
> is
> door een geldig ondertekend document. The views expressed in  this message
> and any annex are purely those of the writer and may not be regarded as 
> stating
> an official position of INBO, as long as the message is not confirmed by a 
> duly
> signed document.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cinci

Re: [R] Creating mixed line and point graphs with xyplot

2009-09-05 Thread jim holtman
I would use the base plot routine

plot(x,c, type='l', ylim=range(a,c))
points(x,a)
park(new=TRUE)
plot(x,d,type='l', ylim=range(b,d), axes=FALSE,ylab='', xlab='')
pints(x,b)
axis(4)

On Fri, Sep 4, 2009 at 11:28 AM, Paul Sweeting wrote:
> Hi
>
> Well, I think the title says it all!  I've looked through the documentation 
> but I can't find a way of doing this.  The situation is that I have 4 series, 
> say a, b, c and d.  Series a and c are plotted on the lh y axis, series b and 
> d are plotted on the rh (secondary) y axis.  I've worked out how to do this.
>
> However, I need to plot series a and b a points (symbols only, no line), 
> whislt c and d need plotting as lines (with no symbols).  What is the easiest 
> way to do this in xyplot?  Or should I be using something else?
>
> Thanks!
>
> Paul
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ggplot2::qplot() -- arbitary transformations of coordinate system?

2009-09-05 Thread Michael Kubovy

Hi,

Does anyone know how to do a coord_trans() in which the y-axis is  
tranformed into (for example) -1000/y?


Thanks,
_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
  McCormick RoadCharlottesville, VA 22903
Office:B011+1-434-982-4729
Lab:B019+1-434-982-4751
Fax:+1-434-982-4766
WWW:http://www.people.virginia.edu/~mk9y/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Video Analysis?

2009-09-05 Thread spencerg
 What software exists for digitizing video to quantify the motion 
of specific features in the image?  I might be willing to use something 
that's NOT in R, though I'd prefer something in R (or at least with an R 
intereface). 



 Thanks,
 Spencer Graves

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] ggplot2::qplot() -- arbitary transformations of coordinate system?

2009-09-05 Thread stephen sefick
why not transform the y-data?

On Sat, Sep 5, 2009 at 8:03 PM, Michael Kubovy wrote:
> Hi,
>
> Does anyone know how to do a coord_trans() in which the y-axis is tranformed
> into (for example) -1000/y?
>
> Thanks,
> _
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
> Parcels:    Room 102        Gilmer Hall
>      McCormick Road    Charlottesville, VA 22903
> Office:    B011    +1-434-982-4729
> Lab:        B019    +1-434-982-4751
> Fax:        +1-434-982-4766
> WWW:    http://www.people.virginia.edu/~mk9y/
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regarding SVM using R

2009-09-05 Thread Steve Lianoglou
Hi Abbas,

Before I try to give you answers, I just want to mention that you
should send R related reqests to the R-help list, and not me
personally because (i) there's a greater likelihood that it will get
answered in a timely manner, and (ii) people who might have a similar
problem down the road might benefit from any answer via searching the
list archives ... anyway:

On Sep 5, 2009, at 1:41 PM, Abbas R. Ali wrote:

> Hi Steve
>
> I need your kind help on implementing SVM using R. I am previously applied 
> neural network technique on the same data and want to get results from SVM as 
> well.
>
> I have 2-D data and want to apply regression on it. After training and 
> prediction I will pass it on my function model_metric(predicted, original, …) 
> to plot the data as I have attached with this email. I want SVM training and 
> prediction source code in R (regression) which can plot my data same as the 
> attached figure.

Use the e1071 package and (i) look at the Example section in ?svm and
(ii) run it to see it work live. There is an example of running
running regression:

R> library(e1071)
R> ?svm
R> example(svm)

You'll see several plots pop up that are very similar to what you're
trying to do.

> On thing is that I have to read data directly from SQL server can you please 
> tell me how can I separate target field from rest of the data (any R command 
> which can separate last field of a matrix).

Figure out what type of database you need to query and get the
appropriate library to do so. Do you mean "sql server" as Microsoft's
SQLServer? Try RODBC, otherwise there's RSQLite, RPostgreSQL, and
RMySQL you can try if you're using those databases.

You can use those libraries to send a sql query to your database and
will be returned a data.frame of your results. You can manipulate that
data.frame in the usual way to pick off your "target" column from. the
predictor/feature columns and train your SVM accordingly (or use the
entire data.frame along with the formula invocation of SVM).

Hope that helps,
-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Video Analysis?

2009-09-05 Thread Kevin Middleton


On Sep 5, 2009, at 5:07 PM, spencerg wrote:

What software exists for digitizing video to quantify the motion  
of specific features in the image?  I might be willing to use  
something that's NOT in R, though I'd prefer something in R (or at  
least with an R intereface).


A few options that I can think of (2 non-R, 1 R):

- If you have access to Matlab, Ty Hedrick (UNC Chapel Hill) has a  
good digitizing program that can handle 3d digitizing with DLT (but  
works fine for 2D), automatic point tracking, reads/writes csv.


http://www.unc.edu/~thedrick/software1.html

- James Rholf's tpsDig (Windows only; http://life.bio.sunysb.edu/ee/rohlf/software.html 
) can be used as a general point digitizer. I think you would have to  
save the videos as image sequences first and reformat the data after.  
I haven't tried this, but I think it would work.


- For one-off, small digitizing projects in R, I have exported videos  
to jpg sequences, loaded them with read.jpeg(), and used locator() for  
digitizing. Negatives: (1) lack of flexibility, (2) very hard to go  
back and fix mistakes, (3) plotting jpeg images is slow unless the  
image dimensions are reduced. But it's a native R solution.


Kevin

-
Kevin M. Middleton
Department of Biology
California State University San Bernardino

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


[R] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread Bryan Hanson
Hello R Folks...

I have a list with the following structure:

> str(df)
List of 3
 $ y: num [1:4, 1:1242] -0.005379 0.029874 -0.023274 0.000655 -0.004537
..
 $ x: num [1:1242] 501 503 505 507 509 ...
 $ names: Factor w/ 4 levels "PC Loading 1",..: 1 2 3 4

I want to plot each row of df$y against df$x, and have each plot in it¹s own
panel according to the levels of df$names.  The following works in the sense
that the layout is right, but the y values have clearly been recycled or
skipped in some fashion (and an error is thrown for each panel that the
length of x and y aren¹t the same):

p <- xyplot(y ~ x | names, data = df, main = title,
layout = c(1, dim(y)[1])

In reviewing the extended formula interface in the Lattice Book, what I want
to happen is y1 + y2 + y3 + y4 ~ x | names, outer = TRUE

I see two options: figure out a way to create the extended formula on the
fly (and the actual number of rows in y may vary), which seems potentially
tricky, or create a data frame by stacking each row of y and repeating x and
names to match.  This seems like a waste of memory.

I¹ve looked through the archives and haven¹t come across something quite
like this, or at least I don¹t recognize it if I have!  Is there a more
elegant way to tell xyplot I want to use each row of y repeatedly with the
same x, in a loop-like fashion?

TIA.  Bryan
*
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA


[[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] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread David Winsemius
I'm not exactly sure what structure df has. Here's my effort to  
duplicate it:


df <- data.frame(y=matrix(rnorm(24), nrow=6), x=1:6)
> df
 y.1y.2y.3y.4 x
1  0.1734636  0.2348417 -1.2375648 -1.3246439 1
2  1.9551669 -1.1027262 -0.7307332  0.3953752 2
3 -0.7645778  1.6297861  0.4743805 -0.4476145 3
4 -0.5308756 -0.5246534 -0.3854609 -1.609 4
5  0.7406525 -0.8691720 -0.8194084  1.6122059 5
6 -0.9625619 -1.0774165  1.0760829  0.3659436 6

And this seems to accomplish the desired task. Presumably you have  
assigned off-stage the value of title to a meaningful character string?


> p <- xyplot(y.1+y.2+y.3+y.4 ~ x |1:4, data = df, main =  
"title" ,layout=c(1,4) )

> p




On Sep 5, 2009, at 11:52 PM, Bryan Hanson wrote:


Hello R Folks...

I have a list with the following structure:


str(df)

List of 3
$ y: num [1:4, 1:1242] -0.005379 0.029874 -0.023274 0.000655  
-0.004537

..
$ x: num [1:1242] 501 503 505 507 509 ...
$ names: Factor w/ 4 levels "PC Loading 1",..: 1 2 3 4

I want to plot each row of df$y against df$x, and have each plot in  
it’s own
panel according to the levels of df$names.  The following works in  
the sense
that the layout is right, but the y values have clearly been  
recycled or
skipped in some fashion (and an error is thrown for each panel that  
the

length of x and y aren’t the same):

p <- xyplot(y ~ x | names, data = df, main = title,
   layout = c(1, dim(y)[1])

In reviewing the extended formula interface in the Lattice Book,  
what I want

to happen is y1 + y2 + y3 + y4 ~ x | names, outer = TRUE

I see two options: figure out a way to create the extended formula  
on the
fly (and the actual number of rows in y may vary), which seems  
potentially
tricky, or create a data frame by stacking each row of y and  
repeating x and

names to match.  This seems like a waste of memory.

I’ve looked through the archives and haven’t come across something  
quite
like this, or at least I don’t recognize it if I have!  Is there a  
more
elegant way to tell xyplot I want to use each row of y repeatedly  
with the

same x, in a loop-like fashion?

TIA.  Bryan
*
Bryan Hanson
Professor of Chemistry & Biochemistry
DePauw University, Greencastle IN USA


[[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
Heritage Laboratories
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] About BIC

2009-09-05 Thread dan . zhao

Hello,

I am working on getting optimal lags by using BIC, But I don't know  
how to calculate BIC. Is there any code or useful function for it?


Thanks and regards,
Dan Zhao

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread Bryan Hanson
Thanks David, your way of constructing df is much more compact than what I
was using, so I've incorporated it.  I also had my rows and columns
transposed relative to how xyplot wanted them (though I had tested for that,
other problems interfered).

In my case, I may have varying numbers of y columns, from y.1 to y.n let's
say.  Is there an easy way of creating the phrase y.1+y.2+...y.n to pass to
xyplot, or even better, some sort of syntax that says "take all y.n" and
plot them against x?

Thanks, Bryan


On 9/6/09 12:51 AM, "David Winsemius"  wrote:

> I'm not exactly sure what structure df has. Here's my effort to
> duplicate it:
> 
> df <- data.frame(y=matrix(rnorm(24), nrow=6), x=1:6)
>> df
>   y.1y.2y.3y.4 x
> 1  0.1734636  0.2348417 -1.2375648 -1.3246439 1
> 2  1.9551669 -1.1027262 -0.7307332  0.3953752 2
> 3 -0.7645778  1.6297861  0.4743805 -0.4476145 3
> 4 -0.5308756 -0.5246534 -0.3854609 -1.609 4
> 5  0.7406525 -0.8691720 -0.8194084  1.6122059 5
> 6 -0.9625619 -1.0774165  1.0760829  0.3659436 6
> 
> And this seems to accomplish the desired task. Presumably you have
> assigned off-stage the value of title to a meaningful character string?
> 
>> p <- xyplot(y.1+y.2+y.3+y.4 ~ x |1:4, data = df, main =
> "title" ,layout=c(1,4) )
>> p
> 
> 
> 
> 
> On Sep 5, 2009, at 11:52 PM, Bryan Hanson wrote:
> 
>> Hello R Folks...
>> 
>> I have a list with the following structure:
>> 
>>> str(df)
>> List of 3
>> $ y: num [1:4, 1:1242] -0.005379 0.029874 -0.023274 0.000655
>> -0.004537
>> ..
>> $ x: num [1:1242] 501 503 505 507 509 ...
>> $ names: Factor w/ 4 levels "PC Loading 1",..: 1 2 3 4
>> 
>> I want to plot each row of df$y against df$x, and have each plot in
>> it¹s own
>> panel according to the levels of df$names.  The following works in
>> the sense
>> that the layout is right, but the y values have clearly been
>> recycled or
>> skipped in some fashion (and an error is thrown for each panel that
>> the
>> length of x and y aren¹t the same):
>> 
>> p <- xyplot(y ~ x | names, data = df, main = title,
>>layout = c(1, dim(y)[1])
>> 
>> In reviewing the extended formula interface in the Lattice Book,
>> what I want
>> to happen is y1 + y2 + y3 + y4 ~ x | names, outer = TRUE
>> 
>> I see two options: figure out a way to create the extended formula
>> on the
>> fly (and the actual number of rows in y may vary), which seems
>> potentially
>> tricky, or create a data frame by stacking each row of y and
>> repeating x and
>> names to match.  This seems like a waste of memory.
>> 
>> I¹ve looked through the archives and haven¹t come across something
>> quite
>> like this, or at least I don¹t recognize it if I have!  Is there a
>> more
>> elegant way to tell xyplot I want to use each row of y repeatedly
>> with the
>> same x, in a loop-like fashion?
>> 
>> TIA.  Bryan
>> *
>> Bryan Hanson
>> Professor of Chemistry & Biochemistry
>> DePauw University, Greencastle IN USA
>> 
>> 
>> [[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
> Heritage Laboratories
> 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] Matrix as input to xyplot {lattice} - proper extended formula syntax

2009-09-05 Thread Gabor Grothendieck
For the example df below this also works:

library(lattice); library(zoo)
xyplot(zoo(df[1:4], df$x), type = "p")

On Sun, Sep 6, 2009 at 12:51 AM, David Winsemius wrote:
> I'm not exactly sure what structure df has. Here's my effort to duplicate
> it:
>
> df <- data.frame(y=matrix(rnorm(24), nrow=6), x=1:6)
>> df
>         y.1        y.2        y.3        y.4 x
> 1  0.1734636  0.2348417 -1.2375648 -1.3246439 1
> 2  1.9551669 -1.1027262 -0.7307332  0.3953752 2
> 3 -0.7645778  1.6297861  0.4743805 -0.4476145 3
> 4 -0.5308756 -0.5246534 -0.3854609 -1.609 4
> 5  0.7406525 -0.8691720 -0.8194084  1.6122059 5
> 6 -0.9625619 -1.0774165  1.0760829  0.3659436 6
>
> And this seems to accomplish the desired task. Presumably you have assigned
> off-stage the value of title to a meaningful character string?
>
>> p <- xyplot(y.1+y.2+y.3+y.4 ~ x |1:4, data = df, main = "title"
>> ,layout=c(1,4) )
>> p
>
>
>
>
> On Sep 5, 2009, at 11:52 PM, Bryan Hanson wrote:
>
>> Hello R Folks...
>>
>> I have a list with the following structure:
>>
>>> str(df)
>>
>> List of 3
>> $ y    : num [1:4, 1:1242] -0.005379 0.029874 -0.023274 0.000655 -0.004537
>> ..
>> $ x    : num [1:1242] 501 503 505 507 509 ...
>> $ names: Factor w/ 4 levels "PC Loading 1",..: 1 2 3 4
>>
>> I want to plot each row of df$y against df$x, and have each plot in it’s
>> own
>> panel according to the levels of df$names.  The following works in the
>> sense
>> that the layout is right, but the y values have clearly been recycled or
>> skipped in some fashion (and an error is thrown for each panel that the
>> length of x and y aren’t the same):
>>
>> p <- xyplot(y ~ x | names, data = df, main = title,
>>       layout = c(1, dim(y)[1])
>>
>> In reviewing the extended formula interface in the Lattice Book, what I
>> want
>> to happen is y1 + y2 + y3 + y4 ~ x | names, outer = TRUE
>>
>> I see two options: figure out a way to create the extended formula on the
>> fly (and the actual number of rows in y may vary), which seems potentially
>> tricky, or create a data frame by stacking each row of y and repeating x
>> and
>> names to match.  This seems like a waste of memory.
>>
>> I’ve looked through the archives and haven’t come across something quite
>> like this, or at least I don’t recognize it if I have!  Is there a more
>> elegant way to tell xyplot I want to use each row of y repeatedly with the
>> same x, in a loop-like fashion?
>>
>> TIA.  Bryan
>> *
>> Bryan Hanson
>> Professor of Chemistry & Biochemistry
>> DePauw University, Greencastle IN USA
>>
>>
>>        [[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
> Heritage Laboratories
> 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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.