var2fact: Rearranges Data for Variables as Factors

Description Usage Arguments Details Value Note Author(s) Examples

Description

Rearranges data from a matrix or data frame into a matrix where data are tagged by their variables names as factors. Used to concatenate data for display with functions tbplots.by.var and bwplots.by.var.

Usage

1
var2fact(xmat)

Arguments

xmat

name of the n by p data matrix or data frame to be processed.

Details

If the data for only some of the variables available in an attached matrix or data frame are to be processed use the cbind construct. Thus, temp.mat <- cbind(vname1, vname3, vname6, vname8).

Value

xx

a n * p by 2 matrix where each of the n * p rows contains a value that is paired with its variable name as a factor, see Note below.

Note

The p variables for n cases results in a n * p by 2 matrix, where [1:n, 1] contains the variable name for value[1] and [1:n, 2] contains the values for the n rows in the first column of xmat. Then rows [n+1:2n, 1] contain the variable name for value[2] and [n+1:2n, 2] contain the values for n rows in the second column, and so on.

Author(s)

Robert G. Garrett

Examples

1
2
3
4
5
6
7
8
## Display, convert data frame and display the result
data(ms.data1)
ms.data1
temp <- var2fact(ms.data1)
temp

## Clean-up
rm(temp)

Example output

Loading required package: MASS
Loading required package: fastICA
     ID   MS.1   MS.2
1  CS01   1.71   2.08
2  CS02   1.01   1.17
3  CS03  33.70  28.80
4  CS04 476.00 451.00
5  CS05 444.00 422.00
6  CS06  75.60  80.40
7  CS07   0.68   0.71
8  CS08   1.68   1.37
9  CS09   0.42   0.41
10 CS10  10.80  11.50
11 CS11 179.00 155.00
12 CS12   1.75   1.65
13 CS13   1.87   1.55
14 CS14 400.00 381.00
15 CS15   0.61   0.65
16 CS16  19.30  24.90
      xx.1   xx.2  
 [1,] "ID"   "1"   
 [2,] "ID"   "2"   
 [3,] "ID"   "3"   
 [4,] "ID"   "4"   
 [5,] "ID"   "5"   
 [6,] "ID"   "6"   
 [7,] "ID"   "7"   
 [8,] "ID"   "8"   
 [9,] "ID"   "9"   
[10,] "ID"   "10"  
[11,] "ID"   "11"  
[12,] "ID"   "12"  
[13,] "ID"   "13"  
[14,] "ID"   "14"  
[15,] "ID"   "15"  
[16,] "ID"   "16"  
[17,] "MS.1" "1.71"
[18,] "MS.1" "1.01"
[19,] "MS.1" "33.7"
[20,] "MS.1" "476" 
[21,] "MS.1" "444" 
[22,] "MS.1" "75.6"
[23,] "MS.1" "0.68"
[24,] "MS.1" "1.68"
[25,] "MS.1" "0.42"
[26,] "MS.1" "10.8"
[27,] "MS.1" "179" 
[28,] "MS.1" "1.75"
[29,] "MS.1" "1.87"
[30,] "MS.1" "400" 
[31,] "MS.1" "0.61"
[32,] "MS.1" "19.3"
[33,] "MS.2" "2.08"
[34,] "MS.2" "1.17"
[35,] "MS.2" "28.8"
[36,] "MS.2" "451" 
[37,] "MS.2" "422" 
[38,] "MS.2" "80.4"
[39,] "MS.2" "0.71"
[40,] "MS.2" "1.37"
[41,] "MS.2" "0.41"
[42,] "MS.2" "11.5"
[43,] "MS.2" "155" 
[44,] "MS.2" "1.65"
[45,] "MS.2" "1.55"
[46,] "MS.2" "381" 
[47,] "MS.2" "0.65"
[48,] "MS.2" "24.9"

rgr documentation built on May 2, 2019, 6:09 a.m.

Related to var2fact in rgr...