[R] issue creating a subset

MacQueen, Don macqueen1 at llnl.gov
Mon Mar 4 16:46:15 CET 2013


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:

> item1 <- item2 <- item3 <- item4 <- 1:4
> 
> matrix1<-cbind(item1, item2, item3, item4)
> 
> z <- c(TRUE,TRUE,FALSE,TRUE)
> 
> matrix2 <- cbind(item1[z], item2[z], item3[z], item4[z])
> 
> matrix3 <- cbind(item1=item1[z], item2=item2[z],
+                  item3=item3[z], item4=item4[z])
> 
> print(matrix1)
     item1 item2 item3 item4
[1,]     1     1     1     1
[2,]     2     2     2     2
[3,]     3     3     3     3
[4,]     4     4     4     4
> 
> print(matrix2)
     [,1] [,2] [,3] [,4]
[1,]    1    1    1    1
[2,]    2    2    2    2
[3,]    4    4    4    4
> 
> print(matrix3)
     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 


-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 2/28/13 5:53 PM, "Pablo Menese" <pmenese at gmail.com> wrote:

I'm performing item response theory with eRm packages
I am excluding the persons that doesn't fit in the infit/outfit persons.
for that I created a condition. then I have to create a new subset or
matrix but with the condition.

So:

ORIGINAL

matrix<-cbind(item1, item2, item3, item4)

IF I PERFORM A head(matrix)

item1 item2 item3 item4
  3         2       3       1
  3         1       2       4

THEN I CREATE THE LOGIC CONDITION

z<-thing==T

THEN I TRY TO CREATE THE NEW MATRIX BUT WITH THE CONDITION

matrix2<-cbind(item1[z==T], item2[z==T], item3[z==T], item4[z==T])

THE ISSUE IS THAT IF I PERFORM A head(matrix2)

 I1        I2       I3      I4
  3         2       3       1
  3         1       2       4

The names of the columns change at all.

CAN ANYONE HELP ME TO KEEP THE SAME NAMES?

	[[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.



More information about the R-help mailing list