Re: [R] How to calculate min of a dataset that contains empty column

2009-09-16 Thread timholland

Presumably there is no reason to attempt plotting an empty column, so best
approach is probably to remove the columns that contain no values.  

Try
> f.temp<-f[,-which(apply(f,2,function(x)all(is.na(x]

and then run your script for f.temp instead of the original f.  

Also, you may find you have to use
> min(x, na.rm=T) 
instead of just
> min(x)
for any other columns that contain NA values as well as real values.  





Chris Li wrote:
> 
> Hi all,
> 
> I have got a dataset like the following:
> 
> a  b  c
> 1  5
> 2
> 3  7
> 
> I am taking the minimum of each column and use it as the minimum of the
> y-axis of my graphs. My scripts (simplified version) are like the
> following:
> 
> f<-array
> f[1]=a
> f[2]=b
> f[3]=c
> for i in 1:3
> name=f[i]
> ymin<-min(dataset$f[i])
> plot(x,y,ylim=c(ymin,100))
> 
> The script stops at b, because the min function returns inf value. What
> can I do to overcome it?
> 
> Many thanks,
> Chris
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-calculate-min-of-a-dataset-that-contains-empty-column-tp25463449p25466916.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] How to calculate min of a dataset that contains empty column

2009-09-16 Thread Tal Galili
Let's say your data.frame is called xx

Then try:
apply(xx,2, function(x) {min(na.omit(x))}  )

Does it work ?





On Wed, Sep 16, 2009 at 2:24 AM, Chris Li wrote:

>
> Hi all,
>
> I have got a dataset like the following:
>
> a  b  c
> 1  5
> 2
> 3  7
>
> I am taking the minimum of each column and use it as the minimum of the
> y-axis of my graphs. My scripts (simplified version) are like the
> following:
>
> f<-array
> f[1]=a
> f[2]=b
> f[3]=c
> for i in 1:3
> name=f[i]
> ymin<-min(dataset$f[i])
> plot(x,y,ylim=c(ymin,100))
>
> The script stops at b, because the min function returns inf value. What can
> I do to overcome it?
>
> Many thanks,
> Chris
> --
> View this message in context:
> http://www.nabble.com/How-to-calculate-min-of-a-dataset-that-contains-empty-column-tp25463449p25463449.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.
>



-- 
--


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
http://www.r-statistics.com/
http://www.talgalili.com
http://www.biostatistics.co.il

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