Dear group, I have the following object> pr_sub$vector[1]14 0.07782809> class( pr_sub$vector[1])[1] "numeric" > length( pr_sub$vector[1]) [1] 1 how can I separate pr_sub$vector[1] and get 14 only thanks in advance Ragia [[alternative HTML version deleted]]
Hi, Ragia, use> names( pr_sub$vector[ 1])Regards -- Gerrit On Tue, 23 Jun 2015, Ragia Ibrahim wrote:> Dear group, > I have the following object > >> pr_sub$vector[1] > 14 > 0.07782809 > >> class( pr_sub$vector[1]) > [1] "numeric" > > > length( pr_sub$vector[1]) > [1] 1 > how can I separate pr_sub$vector[1] > > and get 14 only > > thanks in advance > Ragia > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Dear Group, Kindly, I have those two lines if( (z_nebla==0) || (z_nebla_dash==0) ) CM <- 0 else CM <- 0.5 *(1/a) + 0.5*(1/b) when running it I got this z_nebla==0) logical(0)> (z_nebla_dash==0)logical(0)> (z_nebla==0) || (z_nebla_dash==0)[1] NA why (z_nebla==0) || (z_nebla_dash==0) gives me NA ? thanks in advance Ragia [[alternative HTML version deleted]]
Dear Group, Kindly, I have the following Common_Friends <- intersect(node_neighbours_i_out,node_neighbours_j_out) class(Common_Friends) print(Common_Friends) #4 = Common_Friends newline<-c(i, Common_Friends ) df<- rbind(df,newline) I created a data frame to add the new line when Common_Friends =0 nothing add ?, how to force it to write the value into the data frame Common_Friends <- intersect(node_neighbours_i_out,node_neighbours_j_out)> class(Common_Friends)[1] "numeric"> print(Common_Friends)numeric(0)> newline<-c(i, Common_Friends ) > newline[1] 5 thanks in advance Ragia [[alternative HTML version deleted]]
On Aug 9, 2015, at 8:45 PM, Ragia Ibrahim wrote:> Dear Group, > Kindly, > > I have those two lines > if( (z_nebla==0) || (z_nebla_dash==0) ) > CM <- 0 else > > CM <- 0.5 *(1/a) + 0.5*(1/b) > > when running it > > I got this > > z_nebla==0) > logical(0) >> (z_nebla_dash==0) > logical(0) >> (z_nebla==0) || (z_nebla_dash==0) > [1] NA > > > why (z_nebla==0) || (z_nebla_dash==0) > gives me NA ?We should instead ask you: why should a logical-OR give anything other than NA when given two length-zero vectors as arguments? What value do you expect?> > thanks in advance > Ragia > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 Alameda, CA, USA
The || operator will always return a result of type 'logical' and length 1. You gave it two operands of length 0, so it returned the logical value NA, meaning it had no idea what the result should be. If you give it operands of length > 1, it will use the only the first elements of them. (S and S+ considered length 0 operands to || and && an error and warned about length>1 operands, but R makes no comment about either case). Perhaps you want to use the | operator, which acts like == and +, returning a result as long as the longer of its operands, unless one operand has zero elements, in which case it returns a length 0 result. Bill Dunlap TIBCO Software wdunlap tibco.com On Sun, Aug 9, 2015 at 8:45 PM, Ragia Ibrahim <ragia11 at hotmail.com> wrote:> Dear Group, > Kindly, > > I have those two lines > if( (z_nebla==0) || (z_nebla_dash==0) ) > CM <- 0 else > > CM <- 0.5 *(1/a) + 0.5*(1/b) > > when running it > > I got this > > z_nebla==0) > logical(0) > > (z_nebla_dash==0) > logical(0) > > (z_nebla==0) || (z_nebla_dash==0) > [1] NA > > > why (z_nebla==0) || (z_nebla_dash==0) > gives me NA ? > > thanks in advance > Ragia > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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]]