herbert8686 at gmx.de
2009-Apr-10 09:17 UTC
[R] How to create matrix for if-else application with "i"?
Dear R-friends, Could you please help me with a problem? I have a table with 4 columns: P,Z,S,T. Sometimes z is smaller than s, sometimes z is greater than t. For these smaller/greater z-values, I do need the associated p-value (see example below). I need the whole range of "a" and "b", but I only get the values of "25" for "a" and "5.5" for "b". Also "i" is always "[1]" for all values of p. Could you please help on how to get a matrix form for all separate p-values (for z<s and z>t)? Thanks very much in advance! Herbert ################################# p<-fig8$P z<-fi8a$Z s<-fig8$S t<-fig8$T for(i in 1:length(p)) { if (z[i]<s[i]) { a<-print(p[i]) } else { if (z[i]>t[i]) { b<-print(p[i]) } } } [1] 0.5 [1] 1 [1] 1.5 [1] 2 [1] 2.5 [1] 3 [1] 3.5 [1] 4 [1] 4.5 [1] 5 [1] 5.5 [1] 17 [1] 17.5 [1] 18 [1] 18.5 [1] 19 [1] 19.5 [1] 20 [1] 20.5 [1] 21 [1] 21.5 [1] 22 [1] 22.5 [1] 23 [1] 23.5 [1] 24 [1] 24.5 [1] 25> a[1] 25> b[1] 5.5 ###################### --
herbert8686 at gmx.de
2009-Apr-10 09:54 UTC
[R] How to create matrix for if-else application with "i"?
Dear R-friends, Could you please help me with a problem? I have a table with 4 columns: P,Z,S,T. Sometimes z is smaller than s, sometimes z is greater than t. For these smaller/greater z-values, I do need the associated p-value (see example below). I need the whole range of "a" and "b", but I only get the values of "25" for "a" and "5.5" for "b". Also "i" is always "[1]" for all values of p. Could you please help on how to get a matrix form for all separate p-values (for z<s and z>t)? Thanks very much in advance! Herbert ################################# p<-fig8$P z<-fi8a$Z s<-fig8$S t<-fig8$T for(i in 1:length(p)) { if (z[i]<s[i]) { a<-print(p[i]) } else { if (z[i]>t[i]) { b<-print(p[i]) } } } [1] 0.5 [1] 1 [1] 1.5 [1] 2 [1] 2.5 [1] 3 [1] 3.5 [1] 4 [1] 4.5 [1] 5 [1] 5.5 [1] 17 [1] 17.5 [1] 18 [1] 18.5 [1] 19 [1] 19.5 [1] 20 [1] 20.5 [1] 21 [1] 21.5 [1] 22 [1] 22.5 [1] 23 [1] 23.5 [1] 24 [1] 24.5 [1] 25> a[1] 25> b[1] 5.5 ###################### --
Jim Lemon
2009-Apr-10 10:48 UTC
[R] How to create matrix for if-else application with "i"?
herbert8686 at gmx.de wrote:> Dear R-friends, > > Could you please help me with a problem? > > I have a table with 4 columns: P,Z,S,T. > > Sometimes z is smaller than s, sometimes z is greater than t. For these smaller/greater z-values, I do need the associated p-value (see example below). > > I need the whole range of "a" and "b", but I only get the values of "25" for "a" and "5.5" for "b". > > Also "i" is always "[1]" for all values of p. > > Could you please help on how to get a matrix form for all separate p-values (for z<s and z>t)? > >Hi Herbert, Try this: smallz<-mytable$P[mytable$Z < mytable$S] names(smallz)<-which(mytable$Z < mytable$S) bigz<-mytable$P[mytable$Z > mytable$T] names(bigz)<-which(mytable$Z > mytable$T) The two vectors are unlikely to be the same length (unless there is something I missed) and so making a matrix out of them will probably fail, or at least cause trouble. You could get a list: mynewlist<-list(smallz=smallz,bigz=bigz) Jim
David Winsemius
2009-Apr-10 11:52 UTC
[R] How to create matrix for if-else application with "i"?
Is it really a table? (That is a specific class of object in R.) You seem to be accessing it as a data.frame. Perhaps something along the lines of (untested): subset(fig8, (Z < S | Z > T) )$P -- David Winsemius On Apr 10, 2009, at 5:54 AM, herbert8686 at gmx.de wrote:> Dear R-friends, > > Could you please help me with a problem? > > I have a table with 4 columns: P,Z,S,T. > > Sometimes z is smaller than s, sometimes z is greater than t. For > these smaller/greater z-values, I do need the associated p-value > (see example below). > > I need the whole range of "a" and "b", but I only get the values of > "25" for "a" and "5.5" for "b". > > Also "i" is always "[1]" for all values of p. > > Could you please help on how to get a matrix form for all separate p- > values (for z<s and z>t)? > > Thanks very much in advance! > > Herbert > > > > ################################# > p<-fig8$P > z<-fi8a$Z > s<-fig8$S > t<-fig8$T >David Winsemius, MD Heritage Laboratories West Hartford, CT