Skip to content
Prev 318681 / 398503 Next

issue creating a subset

What Jim said separately is correct, and I would suggest following his
advice.
But there are some points worth looking at in your method.

See this example:
+                  item3=item3[z], item4=item4[z])
item1 item2 item3 item4
[1,]     1     1     1     1
[2,]     2     2     2     2
[3,]     3     3     3     3
[4,]     4     4     4     4
[,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    2    2    2    2
[3,]    4    4    4    4
item1 item2 item3 item4
[1,]     1     1     1     1
[2,]     2     2     2     2
[3,]     4     4     4     4

Points to consider:

Since your "z" is a vector of logical values, you don't need
   item1[z==T]
instead, use
   item1[z]
  
Your column names on matrix2 do not look correct, given how you created
matrix2.

Not that you can specify column names when you create the matrix using
cbind, as in my matrix3 example.

-Don