Dear all I am trying to learn R I was trying to calculate standard deviation here are the commands and outputs in R> sd(Ht_cm[type=='SD'])[1] 3.283605> sd(Ht_cm[from_treeline=='above'])[1] 16.83289> sd(Ht_cm[type=='SD'][from_treeline=='above'])[1] NA>the problem is that, i could not understand why the third command could not give any result. please help me out thanking you Regard MS Nepal _________________________________________________________________ [[elided Hotmail spam]] D24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_myidea:102009 [[alternative HTML version deleted]]
On 26-Oct-09 09:44:55, ms.com wrote:> > Dear all > I am trying to learn R > I was trying to calculate standard deviation > here are the commands and outputs in R >> sd(Ht_cm[type=='SD'])[1] 3.283605 >> sd(Ht_cm[from_treeline=='above'])[1] 16.83289 >> sd(Ht_cm[type=='SD'][from_treeline=='above'])[1] NA > > the problem is that, i could not understand why the third command could > not give any result. > please help me out > thanking you > Regard > MS > NepalThis suggests that either you have only one observation in the third case, or there is an NA amongst them. What are the values of length((Ht_cm[type=='SD'][from_treeline=='above'])[1]) sum(is.na((Ht_cm[type=='SD'][from_treeline=='above'])[1])) sum((type=='SD')&(from_treeline=='above')) sum(type=='SD') sum(from_treeline=='above') The answers to these may provide adequate clues to diagnose the reason. Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 26-Oct-09 Time: 14:28:38 ------------------------------ XFMail ------------------------------
Dear MS, please follow the posting guide and provide reproducible lines of code ! Like this I have no idea what's inside your Ht_cm object . Maybe the problem is that your data might contain NAs, since the basic formula doesn't allow missing values. In this case you have to specify how the function sd() should react. Would you consider removing all elements that are missing as correct ? In order to justify this you should know what your data represent and how much potential bias you're introducing ... Of course the sd() command can't replace your understand of the subjects you're studying .. To illustrate this point : > dat1 <- matrix(c(5,1:5,2,NA),nc=2) > dat1 [,1] [,2] [1,] 5 4 [2,] 1 5 [3,] 2 2 [4,] 3 NA > sd(dat1[,1]) [1] 1.707825 > sd(dat1[,2]) [1] NA ## here I understand the nature of a missing element and judge ## that omitting missing element is acceptable in my study : > sd(dat1[,2],na.rm=T) [1] 1.527525 > sessionInfo() R version 2.9.1 (2009-06-26) i386-pc-mingw32 Hope this helps, Wolfgang ms.com a ?crit :> Dear all > I am trying to learn R > I was trying to calculate standard deviation > here are the commands and outputs in R > >> sd(Ht_cm[type=='SD'])[1] 3.283605> sd(Ht_cm[from_treeline=='above'])[1] 16.83289> sd(Ht_cm[type=='SD'][from_treeline=='above'])[1] NA> >> > > the problem is that, i could not understand why the third command could not give any result. > > please help me out > > thanking you > > Regard > MS > Nepal > _________________________________________________________________ > [[elided Hotmail spam]] > > D24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_myidea:102009 > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > >. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wolfgang Raffelsberger, PhD Laboratoire de BioInformatique et G?nomique Int?gratives CNRS UMR7104, IGBMC, 1 rue Laurent Fries, 67404 Illkirch Strasbourg, France Tel (+33) 388 65 3300 Fax (+33) 388 65 3276 wolfgang.raffelsberger at igbmc.fr
Dear ms. The most possible reason for this:>Dear all >I am trying to learn R >I was trying to calculate standard deviation >here are the commands and outputs in R >> sd(Ht_cm[type=='SD'])[1] 3.283605> sd(Ht_cm[from_treeline=='above'])[1] 16.83289> >sd(Ht_cm[type=='SD'][from_treeline=='above'])[1] NA>>the problem is that, i could not understand why the third command could not give any >result.>please help me out>thanking you>Regard >MS >Nepalis that you're trying to calculate sd over a vector where a NA (Not available) value is contained, that is, you have an empty cell, a different type of data or no data satisfies your condition, try:>sd(Ht_cm[type=='SD'][from_treeline=='above'],na.rm=T)That should do it... -- Marcos Antonio Carvajalino Fern?ndez Estudiante de Ingenier?a Ambiental y Sanitaria Universidad del Magdalena, Colombia