Basic grid manipulations

Displaying a grid
Whenever the name of the variable containing a grid object is typed to the console it is printed. Several datasets are already included in the OpenRepGrid package and are available once the package is loaded. Two of them are bell2010 and fbb2003.

Type one of these variable names to the console andthe grid will be printed.

> bell2010

META DATA: Number of constructs: 9 Number of elements: 10

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: A teacher you respected - 5 6 - Mother (or the person who on of the opposite sex t - 4 | | 7 - A person of the opposit ppiest person you know - 3 | | | | 8 - The most confident pe iend of the same sex - 2 | | | | | | 9 - A person you work w             self - 1 | | | | | | | | 10 - A teacher you di                     | | | | | | | | | |                           relaxed (1)   4 4 6 5 3 6 5 2 2 6   (1) worried & ten (academically) (2)   6 7 6 5 7 4 6 7 4 7   (2) smart (academ islikes sports (3)  6 3 7 6 4 4 2 3 6 3   (3) loves sports ot interactive (4)  6 7 5 6 6 5 6 7 7 4   (4) loves people ot transparent (5)  6 4 5 7 3 7 6 5 6 3   (5) transparent insensitive (6)  4 6 5 4 4 6 5 3 4 2   (6) sensitive fearful&timid (7)  5 4 4 6 5 3 5 6 5 5   (7) fearless rough (8)  5 6 6 4 5 7 7 3 5 6   (8) gentle ccept as it is (9)  5 5 6 7 4 4 6 7 5 5   (9) loves to argu

Usually it is convenient to name an object the way you like to. You can save the grids in any variable you like. To save the grid in the variable x type x <- bell2010

If you now type x to the console the same grid will be printed. > x

META DATA: Number of constructs: 9 Number of elements: 10

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: A teacher you respected - 5 6 - Mother (or the person who on of the opposite sex t - 4 | | 7 - A person of the opposit ppiest person you know - 3 | | | | 8 - The most confident pe iend of the same sex - 2 | | | | | | 9 - A person you work w             self - 1 | | | | | | | | 10 - A teacher you di                     | | | | | | | | | |                           relaxed (1)   4 4 6 5 3 6 5 2 2 6   (1) worried & ten (academically) (2)   6 7 6 5 7 4 6 7 4 7   (2) smart (academ islikes sports (3)  6 3 7 6 4 4 2 3 6 3   (3) loves sports ot interactive (4)  6 7 5 6 6 5 6 7 7 4   (4) loves people ot transparent (5)  6 4 5 7 3 7 6 5 6 3   (5) transparent insensitive (6)  4 6 5 4 4 6 5 3 4 2   (6) sensitive fearful&timid (7)  5 4 4 6 5 3 5 6 5 5   (7) fearless rough (8)  5 6 6 4 5 7 7 3 5 6   (8) gentle ccept as it is (9)  5 5 6 7 4 4 6 7 5 5   (9) loves to argu

Extract a subset of the grid
One of the most powerful operators for repgrid objects is the [ (extract) function. It can be used to access parts of the data and reorder rows and columns. It is applied in the same way as for other R objects (cf. R docu, or type ?Extract to the console). Within the squared brackets the index of the rows (constructs) and/or columns (elements) is supplied determining the order or subset of a grid. E.g. in order to extract the first three rows and first four elements of the bell2010 data use. This will produce a 3x4 subset of the grid you may save to a new object.

> bell2010[1:3, 1:4]

META DATA: Number of constructs: 3 Number of elements: 4

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: iend of the same sex - 2 3 - the unhappiest pers self - 1 | | 4 - A person of the o                    | | | | relaxed (1)  4 4 6 5   (1) worried & ten (academically) (2)  6 7 6 5   (2) smart (academ islikes sports (3)   6 3 7 6   (3) loves sports

Delete elements and/or constructs
Negative indexes indicate that a row and/or column is to be deleted. In order to delete the first construct row (line 1) and the first two elements (line 2) respectively type bell2010[-1, ] bell2010[, -c(1,2)]

Reorder a grid
The brackets function can also be used to reorder a grid. To reverse the order of the constructs type > bell2010[9:1, ]

META DATA: Number of constructs: 9 Number of elements: 10

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: A teacher you respected - 5 6 - Mother (or the person who on of the opposite sex t - 4 | | 7 - A person of the opposit ppiest person you know - 3 | | | | 8 - The most confident pe iend of the same sex - 2 | | | | | | 9 - A person you work w             self - 1 | | | | | | | | 10 - A teacher you di                     | | | | | | | | | |                    ccept as it is (1)   5 5 6 7 4 4 6 7 5 5   (1) loves to argu         rough (2)   5 6 6 4 5 7 7 3 5 6   (2) gentle        fearful&timid (3)   5 4 4 6 5 3 5 6 5 5   (3) fearless        insensitive (4)   4 6 5 4 4 6 5 3 4 2   (4) sensitive    ot transparent (5)   6 4 5 7 3 7 6 5 6 3   (5) transparent  ot interactive (6)   6 7 5 6 6 5 6 7 7 4   (6) loves people islikes sports (7)   6 3 7 6 4 4 2 3 6 3   (7) loves sports (academically) (8)   6 7 6 5 7 4 6 7 4 7   (8) smart (academ relaxed (9)  4 4 6 5 3 6 5 2 2 6   (9) worried & ten

Likewise we can rearrange the order of the elements. In order to facilitate a comparison between the elements self, unhappiest person you know and mother (elements 1, 3 and 6) we may want to rearrange them next to each other. > bell2010[, c(1,3,6,2,4,5, 7:10)]

META DATA: Number of constructs: 9 Number of elements: 10

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: rson of the opposite sex t - 5 6 - A teacher you respected t friend of the same sex - 4 | | 7 - A person of the opposit or the person who fill - 3 | | | | 8 - The most confident pe iest person you know - 2 | | | | | | 9 - A person you work w             self - 1 | | | | | | | | 10 - A teacher you di                     | | | | | | | | | | relaxed (1)  4 6 6 4 5 3 5 2 2 6   (1) worried & ten (academically) (2)  6 6 4 7 5 7 6 7 4 7   (2) smart (academ islikes sports (3)   6 7 4 3 6 4 2 3 6 3   (3) loves sports ot interactive (4)   6 5 5 7 6 6 6 7 7 4   (4) loves people ot transparent (5)   6 5 7 4 7 3 6 5 6 3   (5) transparent     insensitive (6)   4 5 6 6 4 4 5 3 4 2   (6) sensitive     fearful&timid (7)   5 4 3 4 6 5 5 6 5 5   (7) fearless              rough (8)   5 6 7 6 4 5 7 3 5 6   (8) gentle       ccept as it is (9)   5 6 4 5 7 4 6 7 5 5   (9) loves to argu

Moving elements and constructs
Several tasks concerning reordering will be used repeatedly, like e. g. moving a construct upwards. While the extract function can fulfill this task, the code quickly becomes tedious. Hence, specialized functions are available for standard actions. E.g. to move construct 2 upwards the following two lines of code are equivalent. bell2010[c(2,1, 3:9), ] up(bell2010, 2)

The following table lists several functions that provide a shortcut for standard operations.

Swapping poles
Due to the bipolar nature of constructs the direction of a construct is arbitrary. Hence, the poles can also be swapped without affecting the grid information itself. To reflect one or more constructs the function swapPoles can be used. The following code will reflect the constructs one to three. swapPoles(bell2010, 1:3)

Change Ratings
To change single ratings of elements on constructs also the extract function can be used. In this context, the square brackets are used to determine the part of the grid that is assigned new scores. To change the rating in cell (1,1) of the dataset bell2010 to 1 type

bell2010[1,1] <- 1

Likewise, new scores can be assigned to a number of cells in the grid, to whole rows, to whole columns or to the entire grid. The following code gives some examples. x <- bell2010[1:4, 1:5]        # subset of the Bell2010 data set with four rows and five columns

x[1:3, 1] <- c(1,4,3)  	# rows 1 to 3 in column 1 x[1, c(1,4)] <- c(2,2)  	# columns 1 and 4 in row 1 x[1, ] <- c(2,2,1,4,3)		# all columns in row one x[ ,1] <- c(2,2,1,4)		# all rows in column one x[, ] <- c(1,2,3,4,		# whole grid column wise           1,2,3,4,            1,2,3,4,            1,2,3,4,            1,2,3,4)

Modify element and construct names
A grid object contains information about the element and construct labels, their abbreviations, their status (e.g. ideal element or preferred pole). All the information contained in a grid object can be manipulated via the functions setConstructAttr and setElelemntAttr. To e.g. change the construct labels provide the row and the new pole labels to the function.

setConstructAttr(boeker, 1, "new left pole", "new right pole")

To change element the label of the first element, proceed likewise.

setElementAttr(boeker, 1, "new name")

Add elements and constructs
Sometimes it is necessary to add an element or a construct. This can be achieved by modifying the input file itself. Another option is to use the functions addConstruct and addElement</tt>. The following call will add a construct and the corresponding ratings to the bell2010</tt> dataset. The left and right pole are labeled “left pole” and “right pole” respectively.

addConstruct(bell2010, "left pole", "pole right", c(3,1,3,2,5,4,6,3,7,1))

The following code will add an element with the label “new element” to the dataset.

addElement(bell2010, "new element", c(1,2,5,4,3,6,5,2,7))

Defining a grid manually
The import functions make use of internal functions to construct a grid from scratch using the imported data. It is also possible to call these functions manually, an option advanced users may consider. The most convenient way is to use the function makeRepGrid. First a list of arguments (args</tt>) containing the elements and constructs names and the rating scores is created. This list is supplied to the function makeRepGrid</tt>. Note that the scale range has to be set using setScale</tt>, in order to draw the grid properly. Usually it will be more convenient to create a grid via the .txt import function.

args <- list( name= c("element 1", "element 2", "element 3", "element 4", "element 5"),  l.name= c("left pole 1", "left pole 2", "left pole 3", "left pole 4"),  r.name= c("right pole 1", "right pole 2", "right pole3 ", "right pole 4"),  scores= c(4,4,6,5,1, 2,7,6,5,2,           6,3,1,6,4,            6,7,5,6,3)) newGrid <- makeRepgrid(args) newGrid <- setScale(newGrid, 1, 7)

> newGrid

META DATA: Number of constructs: 4 Number of elements: 5

SCALE INFO: The grid is rated on a scale from 1 (left pole) to 7 (right pole)

RATINGS: 3 - element 3 element 2 - 2 | 4 - element 4 element 1 - 1 | | | 5 - element 5 | | | | |                  left pole 1 (1)   4 1 5 1 7   (1) right pole 1 left pole 2 (2)  4 2 2 6 5   (2) right pole 2 left pole 3 (3)  6 7 6 4 6   (3) right pole3 left pole 4 (4)  5 6 3 6 3   (4) right pole 4