[R] How to create matrix for if-else application with "i"?

Jim Lemon jim at bitwrit.com.au
Fri Apr 10 12:48:32 CEST 2009


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




More information about the R-help mailing list