svm predict function error in R - r

I'm trying to run an svm on the titanic data set but I've run into an issue with the predict function.
svm.iceberg <- svm(Survived ~ Pclass+Sex+SibSp+Parch+Ticket+Fare+Cabin+Embarked+Surname+Age_Range, data = train.iceberg)
svm.prediction <- predict(svm.iceberg, newdata = test.iceberg) #prediction
I'm receiving the following error:
Error in names(ret2) <- rowns :'names' attribute [418] must be the same length as the vector [0]
I think the error is a result of when I made the factor levels the same for the train and test data for a few variables (here is the code I used):
test.iceberg$Name <- factor(test.iceberg$Name,levels =levels(train.iceberg$Name))
test.iceberg$Ticket <- factor(test.iceberg$Ticket,levels =levels(train.iceberg$Ticket))
test.iceberg$Cabin <- factor(test.iceberg$Cabin,levels =levels(train.iceberg$Cabin))
test.iceberg$Surname <- factor(test.iceberg$Ticket,levels =levels(train.iceberg$Surname))
Here is the train data frame:
str(train.iceberg)
'data.frame': 891 obs. of 14 variables:
$ PassengerId: int 1 2 3 4 5 6 7 8 9 10 ...
$ Survived : int 0 1 1 1 0 0 0 0 1 1 ...
$ Pclass : Factor w/ 3 levels "1","2","3": 3 1 3 1 3 3 1 3 3 2 ...
$ Name : Factor w/ 891 levels "Abbing, Mr. Anthony",..: 109 191 354 273 16 555 516 625 413 577 ...
$ Sex : Factor w/ 2 levels "female","male": 2 1 1 1 2 2 2 2 1 1 ...
$ Age : num 22 38 26 35 35 NA 54 2 27 14 ...
$ SibSp : int 1 1 0 1 0 0 0 3 0 1 ...
$ Parch : int 0 0 0 0 0 0 0 1 2 0 ...
$ Ticket : Factor w/ 681 levels "110152","110413",..: 524 597 670 50 473 276 86 396 345 133 ...
$ Fare : num 7.25 71.28 7.92 53.1 8.05 ...
$ Cabin : Factor w/ 147 levels "A10","A14","A16",..: NA 82 NA 56 NA NA 130 NA NA NA ...
$ Embarked : Factor w/ 3 levels "C","Q","S": 3 1 3 3 3 2 3 3 3 1 ...
$ Surname : Factor w/ 667 levels "Abbing","Abbott",..: 74 137 252 199 12 410 379 464 293 427 ...
$ Age_Range : num 4 4 4 4 4 NA 4 2 4 3 ...
This caused a lot of NA's in the test data frame as can be seen below:
> str(test.iceberg) #
'data.frame': 418 obs. of 14 variables:
$ PassengerId: int 892 893 894 895 896 897 898 899 900 901 ...
$ Survived : int NA NA NA NA NA NA NA NA NA NA ...
$ Pclass : Factor w/ 3 levels "1","2","3": 3 3 2 3 3 3 3 2 3 3 ...
$ Name : Factor w/ 891 levels "Abbing, Mr. Anthony",..: 434 NA NA NA NA NA 178 NA NA NA ...
$ Sex : Factor w/ 2 levels "female","male": 2 1 2 2 1 2 1 2 1 2 ...
$ Age : num 34 47 62 27 22 14 30 26 18 21 ...
$ SibSp : int 0 1 0 0 1 0 0 1 0 2 ...
$ Parch : int 0 0 0 0 1 0 0 1 0 0 ...
$ Ticket : Factor w/ 681 levels "110152","110413",..: NA NA NA NA 252 NA NA 159 NA 520 ...
$ Fare : num 7.83 7 9.69 8.66 12.29 ...
$ Cabin : Factor w/ 147 levels "A10","A14","A16",..: NA NA NA NA NA NA NA NA NA NA ...
$ Embarked : Factor w/ 3 levels "C","Q","S": 2 3 2 3 3 3 2 3 1 3 ...
$ Surname : Factor w/ 667 levels "Abbing","Abbott",..: NA NA NA NA NA NA NA NA NA NA ...
$ Age_Range : num 5 6 8 5 5 3 5 5 3 5 ...
Here is a sample of the data:
dput((droplevels(head(train.iceberg,100))))
structure(list(PassengerId = 1:100, Survived = c(0L, 1L, 1L,
1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 0L,
1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 0L,
0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L,
0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L,
0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L,
0L), Pclass = structure(c(3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 3L,
2L, 3L, 1L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 2L, 2L, 3L, 1L, 3L,
3L, 3L, 1L, 3L, 3L, 1L, 1L, 3L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L,
2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 2L, 1L, 1L, 2L,
3L, 2L, 3L, 3L, 1L, 1L, 3L, 1L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 2L,
3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, 3L, 1L,
3L, 3L, 3L, 1L, 3L, 3L, 3L, 1L, 1L, 2L, 2L), .Label = c("1",
"2", "3"), class = "factor"), Name = structure(c(12L, 22L, 41L,
32L, 2L, 61L, 56L, 72L, 48L, 64L, 79L, 11L, 80L, 4L, 95L, 42L,
75L, 99L, 94L, 55L, 33L, 9L, 58L, 86L, 73L, 7L, 27L, 31L, 70L,
90L, 92L, 87L, 34L, 98L, 59L, 43L, 54L, 14L, 93L, 65L, 1L, 91L,
51L, 52L, 24L, 76L, 53L, 69L, 78L, 6L, 74L, 66L, 39L, 28L, 71L,
100L, 77L, 67L, 97L, 36L, 83L, 45L, 40L, 84L, 89L, 62L, 68L,
21L, 3L, 50L, 47L, 37L, 44L, 19L, 10L, 60L, 88L, 63L, 13L, 26L,
96L, 81L, 57L, 15L, 46L, 8L, 29L, 85L, 30L, 16L, 18L, 5L, 17L,
23L, 20L, 82L, 35L, 38L, 25L, 49L), .Label = c("Ahlin, Mrs. Johan (Johanna Persdotter Larsson)",
"Allen, Mr. William Henry", "Andersson, Miss. Erna Alexandra",
"Andersson, Mr. Anders Johan", "Andreasson, Mr. Paul Edvin",
"Arnold-Franchi, Mrs. Josef (Josefine Franchi)", "Asplund, Mrs. Carl Oscar (Selma Augusta Emilia Johansson)",
"Backstrom, Mrs. Karl Alfred (Maria Mathilda Gustafsson)", "Beesley, Mr. Lawrence",
"Bing, Mr. Lee", "Bonnell, Miss. Elizabeth", "Braund, Mr. Owen Harris",
"Caldwell, Master. Alden Gates", "Cann, Mr. Ernest Charles",
"Carrau, Mr. Francisco M", "Celotti, Mr. Francesco", "Chaffee, Mr. Herbert Fuller",
"Christmann, Mr. Emil", "Chronopoulos, Mr. Apostolos", "Coxon, Mr. Daniel",
"Crease, Mr. Ernest James", "Cumings, Mrs. John Bradley (Florence Briggs Thayer)",
"Dean, Mr. Bertram Frank", "Devaney, Miss. Margaret Delia", "Doling, Mrs. John T (Ada Julia Bone)",
"Dowdell, Miss. Elizabeth", "Emir, Mr. Farred Chehab", "Faunthorpe, Mrs. Lizzie (Elizabeth Anne Wilkinson)",
"Ford, Mr. William Neal", "Fortune, Miss. Mabel Helen", "Fortune, Mr. Charles Alexander",
"Futrelle, Mrs. Jacques Heath (Lily May Peel)", "Fynney, Mr. Joseph J",
"Glynn, Miss. Mary Agatha", "Goldschmidt, Mr. George B", "Goodwin, Master. William Frederick",
"Goodwin, Miss. Lillian Amy", "Greenfield, Mr. William Bertram",
"Harper, Mrs. Henry Sleeper (Myna Haxtun)", "Harris, Mr. Henry Birkhardt",
"Heikkinen, Miss. Laina", "Hewlett, Mrs. (Mary D Kingcome) ",
"Holverson, Mr. Alexander Oskar", "Hood, Mr. Ambrose Jr", "Icard, Miss. Amelie",
"Ilett, Miss. Bertha", "Jenkin, Mr. Stephen Curnow", "Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg)",
"Kantor, Mr. Sinai", "Kink, Mr. Vincenz", "Kraeff, Mr. Theodor",
"Laroche, Miss. Simonne Marie Anne Andree", "Lennon, Mr. Denis",
"Mamee, Mr. Hanna", "Masselmani, Mrs. Fatima", "McCarthy, Mr. Timothy J",
"McDermott, Miss. Brigdet Delia", "McGowan, Miss. Anna \"Annie\"",
"Meyer, Mr. Edgar Joseph", "Moen, Mr. Sigurd Hansen", "Moran, Mr. James",
"Moubarek, Master. Gerios", "Moutal, Mr. Rahamin Haim", "Nasser, Mrs. Nicholas (Adele Achem)",
"Nicola-Yarred, Miss. Jamila", "Nosworthy, Mr. Richard Cater",
"Novel, Mr. Mansouer", "Nye, Mrs. (Elizabeth Ramell)", "O'Driscoll, Miss. Bridget",
"O'Dwyer, Miss. Ellen \"Nellie\"", "Ostby, Mr. Engelhart Cornelius",
"Palsson, Master. Gosta Leonard", "Palsson, Miss. Torborg Danira",
"Panula, Master. Juha Niilo", "Rice, Master. Eugene", "Rogers, Mr. William John",
"Rugg, Miss. Emily", "Samaan, Mr. Youssef", "Sandstrom, Miss. Marguerite Rut",
"Saundercock, Mr. William Henry", "Sheerlinck, Mr. Jan Baptist",
"Shorney, Mr. Charles Joseph", "Sirayanian, Mr. Orsen", "Skoog, Master. Harald",
"Slocovski, Mr. Selman Francis", "Sloper, Mr. William Thompson",
"Spencer, Mrs. William Augustus (Marie Eugenie)", "Staneff, Mr. Ivan",
"Stewart, Mr. Albert A", "Todoroff, Mr. Lalio", "Turpin, Mrs. William John Robert (Dorothy Ann Wonnacott)",
"Uruchurtu, Don. Manuel E", "Vander Planke, Miss. Augusta Maria",
"Vander Planke, Mrs. Julius (Emelia Maria Vandemoortele)", "Vestrom, Miss. Hulda Amanda Adolfina",
"Waelens, Mr. Achille", "West, Miss. Constance Mirium", "Wheadon, Mr. Edward H",
"Williams, Mr. Charles Eugene", "Woolner, Mr. Hugh"), class = "factor"),
Sex = structure(c(2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L,
1L, 2L, 2L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L,
1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 2L,
2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 2L,
2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L, 1L,
1L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L
), .Label = c("female", "male"), class = "factor"), Age = c(22,
38, 26, 35, 35, NA, 54, 2, 27, 14, 4, 58, 20, 39, 14, 55,
2, NA, 31, NA, 35, 34, 15, 28, 8, 38, NA, 19, NA, NA, 40,
NA, NA, 66, 28, 42, NA, 21, 18, 14, 40, 27, NA, 3, 19, NA,
NA, NA, NA, 18, 7, 21, 49, 29, 65, NA, 21, 28, 5, 11, 22,
38, 45, 4, NA, NA, 29, 19, 17, 26, 32, 16, 21, 26, 32, 25,
NA, NA, 1, 30, 22, 29, NA, 28, 17, 33, 16, NA, 23, 24, 29,
20, 46, 26, 59, NA, 71, 23, 34, 34), SibSp = c(1L, 1L, 0L,
1L, 0L, 0L, 0L, 3L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 4L, 0L,
1L, 0L, 0L, 0L, 0L, 0L, 3L, 1L, 0L, 3L, 0L, 0L, 0L, 1L, 0L,
0L, 1L, 1L, 0L, 0L, 2L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L,
2L, 1L, 4L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 5L, 0L, 0L, 1L,
3L, 0L, 1L, 0L, 0L, 4L, 2L, 0L, 5L, 0L, 1L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 1L, 0L, 3L, 0L, 0L, 0L, 1L,
1L, 0L, 0L, 0L, 0L, 0L, 1L), Parch = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 1L, 2L, 0L, 1L, 0L, 0L, 5L, 0L, 0L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 5L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 2L, 2L, 0L, 0L, 0L, 2L, 0L,
1L, 0L, 0L, 2L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 3L, 0L, 2L, 0L, 0L, 0L, 0L, 2L, 0L,
0L, 0L, 1L, 1L, 0L), Ticket = structure(c(71L, 82L, 95L,
7L, 64L, 36L, 11L, 58L, 52L, 15L, 88L, 4L, 72L, 49L, 59L,
20L, 67L, 18L, 44L, 23L, 16L, 19L, 37L, 5L, 58L, 48L, 22L,
13L, 40L, 55L, 83L, 80L, 41L, 74L, 84L, 6L, 28L, 69L, 45L,
24L, 68L, 8L, 57L, 92L, 39L, 89L, 63L, 9L, 26L, 56L, 34L,
70L, 81L, 31L, 2L, 12L, 76L, 30L, 78L, 79L, 27L, 3L, 62L,
50L, 85L, 25L, 75L, 91L, 33L, 35L, 77L, 79L, 90L, 29L, 10L,
53L, 54L, 65L, 21L, 61L, 46L, 47L, 38L, 1L, 93L, 32L, 96L,
94L, 13L, 42L, 43L, 51L, 97L, 73L, 60L, 66L, 86L, 87L, 14L,
17L), .Label = c("113059", "113509", "113572", "113783",
"113788", "113789", "113803", "11668", "14311", "1601", "17463",
"19947", "19950", "231919", "237736", "239865", "244367",
"244373", "248698", "248706", "248738", "2631", "2649", "2651",
"2661", "2662", "2669", "2677", "2680", "2697", "2926", "3101278",
"3101281", "3101295", "315151", "330877", "330923", "330932",
"330958", "330959", "335677", "343275", "343276", "345763",
"345764", "345767", "345779", "347077", "347082", "347088",
"347466", "347742", "348123", "349208", "349216", "349237",
"349253", "349909", "350406", "364500", "364516", "36973",
"370371", "373450", "374746", "374910", "382652", "7546",
"A./5. 2152", "A/4. 39886", "A/5 21171", "A/5. 2151", "C.A. 2315",
"C.A. 24579", "C.A. 29395", "C.A. 31026", "C.A. 33111", "C.A. 34651",
"CA 2144", "PC 17569", "PC 17572", "PC 17599", "PC 17601",
"PC 17604", "PC 17605", "PC 17754", "PC 17759", "PP 9549",
"S.C./A.4. 23567", "S.O.C. 14879", "S.P. 3464", "SC/Paris 2123",
"SO/C 14885", "SOTON/OQ 392086", "STON/O2. 3101282", "W./C. 6608",
"W.E.P. 5734"), class = "factor"), Fare = c(7.25, 71.2833,
7.925, 53.1, 8.05, 8.4583, 51.8625, 21.075, 11.1333, 30.0708,
16.7, 26.55, 8.05, 31.275, 7.8542, 16, 29.125, 13, 18, 7.225,
26, 13, 8.0292, 35.5, 21.075, 31.3875, 7.225, 263, 7.8792,
7.8958, 27.7208, 146.5208, 7.75, 10.5, 82.1708, 52, 7.2292,
8.05, 18, 11.2417, 9.475, 21, 7.8958, 41.5792, 7.8792, 8.05,
15.5, 7.75, 21.6792, 17.8, 39.6875, 7.8, 76.7292, 26, 61.9792,
35.5, 10.5, 7.2292, 27.75, 46.9, 7.2292, 80, 83.475, 27.9,
27.7208, 15.2458, 10.5, 8.1583, 7.925, 8.6625, 10.5, 46.9,
73.5, 14.4542, 56.4958, 7.65, 7.8958, 8.05, 29, 12.475, 9,
9.5, 7.7875, 47.1, 10.5, 15.85, 34.375, 8.05, 263, 8.05,
8.05, 7.8542, 61.175, 20.575, 7.25, 8.05, 34.6542, 63.3583,
23, 26), Cabin = structure(c(NA, 11L, NA, 7L, NA, NA, 16L,
NA, NA, NA, 19L, 6L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
14L, NA, 2L, NA, NA, NA, 8L, NA, NA, NA, 5L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 13L, NA, 4L, 9L, NA, NA, NA, NA, NA, 3L, 10L, NA,
NA, NA, 18L, NA, NA, NA, NA, NA, NA, NA, NA, 17L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 8L, NA, NA, NA, 15L,
NA, NA, NA, 1L, 12L, NA, NA), .Label = c("A5", "A6", "B28",
"B30", "B78", "C103", "C123", "C23 C25 C27", "C52", "C83",
"C85", "D10 D12", "D33", "D56", "E31", "E46", "F G73", "F33",
"G6"), class = "factor"), Embarked = structure(c(3L, 1L,
3L, 3L, 3L, 2L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 2L,
3L, 3L, 1L, 3L, 3L, 2L, 3L, 3L, 3L, 1L, 3L, 2L, 3L, 1L, 1L,
2L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 3L, 1L, 1L, 2L, 3L, 2L,
2L, 1L, 3L, 3L, 3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 3L, 1L, NA,
3L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L), .Label = c("C", "Q", "S"
), class = "factor"), Surname = structure(c(11L, 21L, 38L,
30L, 2L, 58L, 53L, 69L, 45L, 61L, 75L, 10L, 76L, 3L, 90L,
39L, 71L, 94L, 89L, 52L, 31L, 8L, 55L, 82L, 69L, 6L, 26L,
29L, 67L, 86L, 88L, 83L, 32L, 93L, 56L, 40L, 51L, 13L, 89L,
62L, 1L, 87L, 48L, 49L, 23L, 72L, 50L, 66L, 74L, 5L, 70L,
63L, 36L, 27L, 68L, 95L, 73L, 64L, 92L, 34L, 79L, 42L, 37L,
80L, 85L, 59L, 65L, 20L, 3L, 47L, 44L, 34L, 41L, 18L, 9L,
57L, 84L, 60L, 12L, 25L, 91L, 77L, 54L, 14L, 43L, 7L, 28L,
81L, 29L, 15L, 17L, 4L, 16L, 22L, 19L, 78L, 33L, 35L, 24L,
46L), .Label = c("Ahlin", "Allen", "Andersson", "Andreasson",
"Arnold-Franchi", "Asplund", "Backstrom", "Beesley", "Bing",
"Bonnell", "Braund", "Caldwell", "Cann", "Carrau", "Celotti",
"Chaffee", "Christmann", "Chronopoulos", "Coxon", "Crease",
"Cumings", "Dean", "Devaney", "Doling", "Dowdell", "Emir",
"Faunthorpe", "Ford", "Fortune", "Futrelle", "Fynney", "Glynn",
"Goldschmidt", "Goodwin", "Greenfield", "Harper", "Harris",
"Heikkinen", "Hewlett", "Holverson", "Hood", "Icard", "Ilett",
"Jenkin", "Johnson", "Kantor", "Kink", "Kraeff", "Laroche",
"Lennon", "Mamee", "Masselmani", "McCarthy", "McDermott",
"McGowan", "Meyer", "Moen", "Moran", "Moubarek", "Moutal",
"Nasser", "Nicola-Yarred", "Nosworthy", "Novel", "Nye", "O'Driscoll",
"O'Dwyer", "Ostby", "Palsson", "Panula", "Rice", "Rogers",
"Rugg", "Samaan", "Sandstrom", "Saundercock", "Sheerlinck",
"Shorney", "Sirayanian", "Skoog", "Slocovski", "Sloper",
"Spencer", "Staneff", "Stewart", "Todoroff", "Turpin", "Uruchurtu",
"Vander Planke", "Vestrom", "Waelens", "West", "Wheadon",
"Williams", "Woolner"), class = "factor"), Age_Range = c(4,
4, 4, 4, 4, NA, 4, 2, 4, 3, 2, 4, 4, 4, 3, 4, 2, NA, 4, NA,
4, 4, 3, 4, 2, 4, NA, 3, NA, NA, 6, NA, NA, 8, 5, 6, NA,
5, 3, 3, 6, 5, NA, 2, 3, NA, NA, NA, NA, 3, 2, 5, 6, 5, 8,
NA, 5, 5, 2, 2, 5, 5, 6, 2, NA, NA, 5, 3, 3, 5, 5, 3, 5,
5, 5, 5, NA, NA, 1, 5, 5, 5, NA, 5, 3, 5, 3, NA, 5, 5, 5,
5, 6, 5, 7, NA, 9, 5, 5, 5)), .Names = c("PassengerId", "Survived",
"Pclass", "Name", "Sex", "Age", "SibSp", "Parch", "Ticket", "Fare",
"Cabin", "Embarked", "Surname", "Age_Range"), row.names = c(NA,
100L), class = "data.frame")

Related

Creating a new dataframe with averages from another dataframe with multiple conditions in R

I have fish count data and am trying to create a new dataframe using averages of the measurements based on conditions of two different columns. here is my data:
df <- structure(list(SITE = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L,
3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L,
2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L,
2L, 2L, 2L, 3L, 3L, 3L), .Label = c("1", "2", "3"), class = "factor"),
ZONE = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L), .Label = c("CREST", "INNER_FLAT", "MID_FLAT",
"OUTER_FLAT", "SLOPE"), class = "factor"), C_TOTAL = c(44L,
7L, 20L, 14L, 0L, 4L, 2L, 3L, 1L, 8L, 28L, 24L, 31L, 12L,
33L, 6L, 16L, 33L, 75L, 21L, 60L, 81L, 37L, 89L, 21L, 35L,
71L, 5L, 2L, 0L, 0L, 10L, 23L, 0L, 5L, 11L, 3L, 1L, 5L, 0L,
0L, 8L, 7L, 6L, 42L), C_M2 = c(0.210465706, 0.029861994,
0.090324177, 0.066599319, 0, 0.022092452, 0.011750593, 0.015245519,
0.004710433, 0.033111594, 0.155094195, 0.110576495, 0.193659068,
0.059152822, 0.192379108, 0.047800772, 0.08917095, 0.141336411,
0.402538785, 0.130438337, 0.315206235, 0.460746849, 0.278643938,
0.467754275, 0.192830321, 0.119928472, 0.411502497, 0.015370489,
0.005150184, 0, 0, 0.034651441, 0.067824733, 0, 0.009805851,
0.034844309, 0.010614352, 0.004131048, 0.01850898, 0, 0,
0.029195413, 0.021409016, 0.030498145, 0.172406074), TRANS_A = c(209.0601875,
234.411677, 221.4246571, 210.2123593, 226.6158348, 181.0573136,
170.2041767, 196.7791332, 212.294701, 241.6072127, 180.5354478,
217.0443184, 160.0751279, 202.8643689, 171.536298, 125.5209863,
179.4306337, 233.485481, 186.3174499, 160.9956132, 190.3515643,
175.801528, 132.7859497, 190.2708425, 108.9040348, 291.8406241,
172.5384427, 325.2986863, 388.3356059, 303.1957479, 261.1574528,
288.5882879, 339.1093313, 239.1118021, 509.89965, 315.6899993,
282.6362022, 242.0693453, 270.1391425, 294.8864591, 321.2013381,
274.0156514, 326.9650539, 196.7332763, 243.6109069), SCARID_T = c(35L,
4L, 4L, 13L, 0L, 4L, 2L, 0L, 1L, 4L, 20L, 12L, 17L, 5L, 20L,
6L, 6L, 18L, 63L, 11L, 41L, 75L, 34L, 89L, 14L, 33L, 68L,
0L, 0L, 0L, 0L, 10L, 22L, 0L, 0L, 10L, 0L, 0L, 1L, 0L, 0L,
6L, 0L, 4L, 42L), ACAN_T = c(4L, 0L, 11L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 8L, 5L, 0L, 0L, 0L, 0L, 3L, 2L, 7L, 8L, 8L, 1L,
1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 5L, 0L, 0L,
0L, 1L, 0L, 0L, 2L, 0L, 0L, 0L), SIG_T = c(5L, 3L, 5L, 1L,
0L, 0L, 0L, 3L, 0L, 4L, 0L, 7L, 14L, 7L, 13L, 0L, 7L, 13L,
5L, 2L, 11L, 5L, 2L, 0L, 7L, 1L, 3L, 5L, 2L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 3L, 1L, 3L, 0L, 0L, 0L, 7L, 2L, 0L)), row.names = c(NA,
-45L), class = "data.frame")
I want to average all the measurements by each zone, but also according to site. So I want anew data frame where each site has one measurement for each zone.
Can anyone help me? Thanks!
library(dplyr)
df %>%
group_by(SITE, ZONE) %>%
summarise(
across(where(is.numeric), mean)
)
# A tibble: 15 x 8
# Groups: SITE [3]
SITE ZONE C_TOTAL C_M2 TRANS_A SCARID_T ACAN_T SIG_T
<fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1 CREST 20 0.0996 213. 12 4.33 3.67
2 1 INNER_FLAT 3 0.0111 265. 0.333 0.333 2.33
3 1 MID_FLAT 2.33 0.00684 339. 0 0 2.33
4 1 OUTER_FLAT 52 0.283 179. 38.3 7.67 6
5 1 SLOPE 23.7 0.110 222. 14.3 5 4.33
6 2 CREST 25.3 0.148 178. 14 0 11.3
7 2 INNER_FLAT 2.67 0.00973 297. 2 0.667 0
8 2 MID_FLAT 11 0.0342 296. 10.7 0.333 0
9 2 OUTER_FLAT 69 0.402 166. 66 0.667 2.33
10 2 SLOPE 6 0.0296 206. 5.67 0 0.333
11 3 CREST 18.3 0.0928 179. 10 1.67 6.67
12 3 INNER_FLAT 18.3 0.0748 256. 15.3 0 3
13 3 MID_FLAT 5.33 0.0149 355. 3.33 1.67 0.333
14 3 OUTER_FLAT 42.3 0.241 191. 38.3 0.333 3.67
15 3 SLOPE 2 0.0106 193. 1 0 1

reshape data frame and concatenating columns in R

I tried to reshape my data frame from wide to long format. At the moment the data frame looks like this:
structure(list(study_site = structure(c(5L, 5L, 5L, 5L, 5L, 5L,
5L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 4L, 4L, 1L, 2L, 3L, 1L, 4L, 1L,
4L, 3L, 3L, 3L, 1L, 3L, 5L, 4L, 4L, 4L, 3L, 3L, 5L, 5L, 4L, 4L,
4L, 1L, 4L, 3L, 5L, 5L, 5L, 1L, 3L, 5L, 3L, 3L, 3L, 5L, 5L, 3L,
4L, 2L), .Label = c("N", "no_nest", "O", "S", "W"), class = "factor"),
coords.N = structure(c(54L, 54L, 40L, 40L, 40L, 40L, 39L,
67L, 67L, 55L, 55L, 64L, 64L, 64L, 78L, 81L, 47L, 80L, 83L,
60L, 46L, 46L, 76L, 88L, 88L, 88L, 84L, 84L, 30L, 58L, 58L,
58L, 25L, 25L, 19L, 19L, 42L, 42L, 42L, 29L, 45L, 90L, 91L,
91L, 91L, 91L, 89L, 89L, 87L, 87L, 87L, 56L, 56L, 61L, 35L,
36L), .Label = c("40.40463", "48.40168", "48.40178", "48.40215",
"48.40235", "48.40309", "48.40390", "48.40393", "48.40396",
"48.40405", "48.40410", "48.40411", "48.40415", "48.40416",
"48.40424", "48.40425", "48.40430", "48.40435", "48.40436 ",
"48.40438", "48.40443", "48.40450", "48.40451", "48.40454",
"48.40455", "48.40459", "48.40460", "48.40461", "48.40466",
"48.40466 ", "48.40467", "48.40469", "48.40471", "48.40477",
"48.40479 ", "48.40481", "48.40482", "48.40483", "48.40488 ",
"48.40491", "48.40493", "48.40504 ", "48.40508", "48.40513",
"48.40515", "48.40519 ", "48.40522 ", "48.40523", "48.40525",
"48.40526", "48.40529", "48.40532", "48.40537", "48.40537 ",
"48.40538 ", "48.40543 ", "48.40549", "48.40549 ", "48.40557",
"48.40557 ", "48.40558", "48.40565", "48.40571", "48.40575",
"48.40580", "48.40584", "48.40586 ", "48.40591", "48.40596",
"48.40598", "48.40599", "48.40611", "48.40612", "48.40617",
"48.40626", "48.40632 ", "48.40633", "48.40635 ", "48.40636",
"48.40637", "48.40638 ", "48.40639", "48.40639 ", "48.40641 ",
"48.40652", "48.40655", "48.40656 ", "48.40657 ", "48.40687 ",
"48.40690 ", "48.40703", "48.40718", "48.40719", "48.40726",
"48.40742", "48.40748", "NO_DATA"), class = "factor"), coords.E = structure(c(67L,
67L, 49L, 49L, 49L, 49L, 27L, 67L, 67L, 70L, 70L, 68L, 68L,
68L, 87L, 94L, 68L, 83L, 90L, 73L, 52L, 52L, 2L, 95L, 95L,
95L, 93L, 93L, 32L, 69L, 69L, 69L, 55L, 55L, 24L, 24L, 29L,
29L, 29L, 30L, 48L, 85L, 1L, 1L, 1L, 1L, 78L, 78L, 79L, 79L,
79L, 64L, 64L, 63L, 66L, 45L), .Label = c(" 015.82024", " 015.82164",
"015.80237", "015.80263", "015.80309", "015.80341", "015.80369",
"015.80388", "015.80394", "015.80399", "015.80406", "015.80435",
"015.80436", "015.80466", "015.80512", "015.80517", "015.80548",
"015.80551", "015.80572", "015.80583", "015.80609", "015.80636",
"015.80659", "015.80703", "015.80723", "015.80779", "015.80795",
"015.80803", "015.80821", "015.80843", "015.80871", "015.80875",
"015.80888", "015.80897", "015.80901", "015.80903", "015.80905",
"015.80906", "015.80908", "015.80909", "015.80921", "015.80923",
"015.80929", "015.80939", "015.80993", "015.81007", "015.81018",
"015.81087", "015.81113", "015.81132", "015.81151", "015.81180",
"015.81241", "015.81273", "015.81305", "015.81406", "015.81422",
"015.81522", "015.81526", "015.81543", "015.81546", "015.81564",
"015.81628", "015.81632", "015.81678", "015.81682", "015.81700",
"015.81703", "015.81735", "015.81739", "015.81770", "015.81783",
"015.81784", "015.81800", "015.81849", "015.81992", "015.82012",
"015.82029", "015.82039", "015.82083", "015.82099", "015.82126",
"015.82180", "015.82230", "015.82232", "015.82255", "015.82265",
"015.82290", "015.82303", "015.82304", "015.82346", "015.82362",
"015.82376", "015.82398", "015.82451", "015.82500", "015.82519",
"015.82555", "015.82579", "015.82634", "NO_DATA"), class = "factor"),
study_ID = c(120L, 120L, 1L, 1L, 1L, 1L, 9L, 39L, 39L, 109L,
109L, 110L, 110L, 110L, 45L, 58L, 121L, 96L, 97L, 40L, 43L,
43L, 47L, 57L, 57L, 57L, 114L, 114L, 67L, 71L, 71L, 71L,
83L, 83L, 4L, 4L, 10L, 10L, 10L, 106L, 108L, 46L, 115L, 115L,
115L, 115L, 116L, 116L, 117L, 117L, 117L, 70L, 70L, 119L,
95L, 3L), species = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L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 0L, 0L, 0L, 0L, 0L,
1L, 0L, 0L), used_2nd_visit = c(0L, 2L, 1L, 0L, 0L, 0L, 1L,
0L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 2L, 0L,
4L, 0L, 0L, 0L, 1L, 0L, 5L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L,
0L, 0L, 0L, 0L), used_3rd_visit = c(0L, 0L, 1L, 0L, 0L, 0L,
1L, 0L, 1L, 0L, 4L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 2L, 0L, 1L, 0L, 2L,
0L, 0L, 6L, 1L, 0L, 1L, 0L, 0L, 2L, 0L, 0L, 1L, 0L, 0L, 2L,
0L, 1L, 0L, 0L, 0L), nest_condition = structure(c(3L, 5L,
5L, 2L, 5L, 5L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 2L, 5L, 3L, 2L,
4L, 5L, 5L, 5L, 5L, 3L, 2L, 5L, 5L, 2L, 2L, 5L, 1L, 5L, 5L,
5L, 5L, 5L, 5L, 3L, 5L, 5L, 5L, 2L, 3L, 5L, 5L, 5L, 2L, 5L,
3L, 5L, 5L, 5L, 2L, 5L, 3L, 5L, 4L), .Label = c(" ready ",
"damaged", "in_progress", "no_nest", "ready"), class = "factor"),
nesting_site = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 3L, 1L,
1L, 1L, 1L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L), .Label = c("inside", "no_nest", "outside"), class = "factor"),
distance = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 4L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 4L, 3L, 6L, 4L, 4L, 2L, 2L, 4L, 2L,
2L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
3L, 2L, 4L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
4L, 6L), .Label = c("1", "2", "3", "4", "no_data", "no_nest"
), class = "factor"), material = structure(c(5L, 5L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 5L, 5L, 1L, 1L, 2L), .Label = c("fine", "fine plaster",
"medium fine plaster", "no_data", "rough", "rough plaster",
"smooth plaster", "under construction", "wood"), class = "factor"),
housetype = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 5L, 4L, 4L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 5L, 5L, 5L,
4L, 4L, 5L, 3L, 3L, 3L, 3L, 5L, 5L, 3L, 3L, 3L, 4L, 4L, 5L,
5L, 4L), .Label = c("auto repair shop", "barn ", "hall",
"residence", "stable"), class = "factor"), usage_house = structure(c(5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 3L), .Label = c("auto_repair",
"barn", "inhabited", "under construction", "used"), class = "factor"),
age = c(1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L)), row.names = c(1L,
2L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L,
19L, 21L, 22L, 23L, 24L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L,
35L, 36L, 37L, 38L, 39L, 40L, 41L, 89L, 90L, 91L, 92L, 93L, 94L,
95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L,
106L, 107L, 108L, 109L, 111L), class = "data.frame")
used_1st..2nd... means that the birds have used this certain number of nests at the first, second,... control.
I would like to have that each row in my data frame to always represent a used/ unused nest as well as no_nest:
ID species `1st_visit` `2nd_visit` `3rd_visit` used_1st_visit used_2nd_visit used_3rd_visit
<dbl> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 120 barn s~ 1 1 0 0 0 0
2 120 barn s~ 1 1 0 1 1 0
3 120 barn s~ 1 1 0 1 1 0
4 39 barn s~ 1 1 1 1 1 1
5 8 barn s~ 1 1 1 1 0 0
6 8 barn s~ 1 1 1 0 0 0
Unfortunately I have no idea how to concatenate the columns to get the final data frame.
Does anybody has an idea?
I'm not completely sure what you are asking for, but this is what I understood: In the long data frame...
if all visits (coulmns used_first_visit, used_sec_visit etc.) are 0, combine them to one row, marking it 0
if any visits are not 0, keep as many rows as there are non-zero visits and mark them with 1
This is my dplyr-solution (it's not very pretty, but it works):
# create data
dat <- data.frame("visits" = c("first", "first", "second", "second", "third", "third"), "study_id" = rep(120, 6), "used_first_visit" = c(0, 2, 0, 2, 0, 2), "used_sec_visit" = c(0, 2, 0, 2, 0, 2), "used_thrd_visit" = rep(0, 6), "nest_cond" = c("damaged", "ready", "damaged", "ready", "damaged", "ready"))
# make long data frame and filter values
dat_long <- dat %>%
pivot_longer(c(3:5),names_to = "whatever", values_to = "used") %>% # make long data frame
select(-c(whatever)) %>% # get rid of name column
group_by(visits, nest_cond) %>% # group data
mutate(used = ifelse(all(used == 0) & row_number() == 1, 10, used)) %>% # if the whole group is 0, mark one row for later filtering
filter(used > 0 ) %>% # filter
mutate(used = ifelse(used == 10, 0, 1)) # change to correct numbers
Let me know if this is not what you are looking for!

Re arrange eye tracking data

I have an eye tracking data file which I need to transform. Let me explain, my data are formated like this:
Event; Info; Pupil size
Message; Start_trial_0;
Fixation; L; 1020
Fixation; L; 1200
Fixation; L; 980
Fixation; L; 990
Fixation; L; 1003
Message; Trial_0;
Message; ACC_1;
Message; RT_850;
Message; Stop_trial_0;
Message; Start_trial_1;
Fixation; L; 1023
Fixation; L; 1020
Fixation; L; 997
Fixation; L; 1123
Message; Trial_1;
Message; ACC_1;
Message; RT_920;
Message; Stop_trial_1;
Message; Strat_trial_2;
...
Knowing that, I never have the same number of "Fixation" line for each trial.
I want my data to be like that:
Trial_0; ACC_0; RT_850; Fixation; L; 1020
Trial_0; ACC_0; RT_850; Fixation; L; 1200
Trial_0; ACC_0; RT_850; Fixation; L; 980
Trial_0; ACC_0; RT_850; Fixation; L; 990
Trial_0; ACC_0; RT_850; Fixation; L; 1003
Trial_1; ACC_1; RT_920; Fixation; L; 1023
Trial_1; ACC_1; RT_920; Fixation; L; 1020
Trial_1; ACC_1; RT_920; Fixation; L; 997
Trial_1; ACC_1; RT_920; Fixation; L; 1123
...
As I'm not an experimented R user, I absolutely don't know how to do that (if it's possible). And as my data file contain over 1000000 lines, it cannot be done manually ...
Thanks in advance for your precious help !
Jibs.
The general approach is to split your lines into buckets of all the same trial, then pull out the metadata vs data lines, and make them into a dataframe (assuming that's what you ultimately want).
library(stringr)
library(purrr)
# You may be reading this in with `readLines` or similar,
# in which case you may not need to split on "\n" below
eye_text <-
"Event; Info; Pupil size
Message; Start_trial_0;
Fixation; L; 1020
Fixation; L; 1200
Fixation; L; 980
Fixation; L; 990
Fixation; L; 1003
Message; Trial_0;
Message; ACC_1;
Message; RT_850;
Message; Stop_trial_0;
Message; Start_trial_1;
Fixation; L; 1023
Fixation; L; 1020
Fixation; L; 997
Fixation; L; 1123
Message; Trial_1;
Message; ACC_1;
Message; RT_920;
Message; Stop_trial_1;
Message; Start_trial_2;" # Fixed typo?
# Depending how you read in the data, may already be a vector of lines
eye_lines <- str_split(eye_text, "\n")[[1]]
# Figure out where each trial starts
eye_starts <- cumsum(str_detect(eye_lines, "Start"))
Split the data
str_detect(eye_lines, "Start") gives you a vector of TRUE/FALSE indicating the start of each trial. cumsum coerces that to 1/0 and takes the running total. This way you end up with 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3, or four groups from the sample text (the header, Trial 0, Trial 1, and one line of Trial 2).
eye_parser <- function(strings) {
message_indices <- str_detect(strings, "Message;") & !str_detect(strings, "Start|Stop")
messages <-
strings[message_indices] %>%
str_remove_all("Message; ") %>%
str_c(collapse = " ")
if (length(messages) == 0) return(NULL)
observations <- strings[!str_detect(strings, "Message")]
str_c(messages, observations, sep = " ")
}
Here we subset the strings twice: first we get all the Message; lines (but not the Start*/Stop* lines), then we get all the non-Message; lines.
For the messages, we strip out "Message; ", which leaves you with the metadata values (a vector of "Trial_0;", "ACC_1;", ... etc). Then you str_c those all back together into a single metadata line: "Trial_0; ACC_1; RT_850;".
At this point if the messages are all empty (like the header and partial trial), we just return NULL.
For the observations, we just take them as is. Then we str_c the messages and observations together, repeating messages in front of every observation line.
To use this function, we first split all your lines into the groups from above, then purrr::map the function over each group of strings. unlist takes it from a list of vectors to a single vector, and then str_split(..., "; ", simplify = T) breaks it out into a character matrix with columns. Finally as.data.frame makes it into a dataframe.
split(eye_lines, eye_starts) %>%
map(eye_parser) %>%
unlist(use.names = F) %>%
str_split("; ", simplify = T) %>%
as.data.frame()
V1 V2 V3 V4 V5 V6
1 Trial_0 ACC_1 RT_850 Fixation L 1020
2 Trial_0 ACC_1 RT_850 Fixation L 1200
3 Trial_0 ACC_1 RT_850 Fixation L 980
4 Trial_0 ACC_1 RT_850 Fixation L 990
5 Trial_0 ACC_1 RT_850 Fixation L 1003
6 Trial_1 ACC_1 RT_920 Fixation L 1023
7 Trial_1 ACC_1 RT_920 Fixation L 1020
8 Trial_1 ACC_1 RT_920 Fixation L 997
9 Trial_1 ACC_1 RT_920 Fixation L 1123
Caveats:
If your metadata isn't always exactly "Trial", "ACC", "RT" in that order, you'll probably want to extract those specifically. You can use the same code pattern I used for messages but for each of those individually. Then you can make sure they're present and in the correct order.
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,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 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("EFI",
"MSG"), class = "factor"), Info = structure(c(127L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 172L, 51L, 128L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
11L, 1L, 220L, 3L, 95L, 7L, 218L, 173L, 129L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 35L, 61L, 219L, 3L, 86L, 7L, 218L, 174L, 140L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 41L, 66L, 219L,
3L, 107L, 7L, 216L, 185L, 51L, 151L, 51L, 51L, 51L, 51L, 27L,
83L, 220L, 3L, 98L, 7L, 216L, 196L, 162L, 51L, 51L, 51L, 51L,
51L, 30L, 57L, 219L, 3L, 88L, 7L, 217L, 207L, 167L, 51L, 51L,
51L, 51L, 51L, 51L, 36L, 62L, 220L, 3L, 93L, 7L, 217L, 211L,
168L, 51L, 51L, 51L, 51L, 48L, 71L, 219L, 3L, 85L, 7L, 216L,
212L, 169L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 26L, 83L,
220L, 3L, 102L, 7L, 216L, 213L, 170L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 29L, 56L, 220L, 3L, 101L, 4L, 218L, 214L, 51L, 171L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 49L, 72L, 220L, 2L, 103L,
4L, 216L, 215L, 130L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 20L, 80L, 219L, 3L, 116L, 4L, 218L, 175L, 131L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 25L, 83L, 219L, 3L, 125L, 4L, 216L, 176L, 132L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 32L, 52L, 219L, 3L, 126L, 4L, 218L,
177L, 133L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 8L,
53L, 220L, 3L, 97L, 4L, 218L, 178L, 134L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 40L, 65L, 219L,
3L, 117L, 4L, 216L, 179L, 135L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 9L, 74L, 220L,
3L, 121L, 4L, 216L, 180L, 136L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 28L, 55L, 220L, 3L, 84L, 6L, 218L, 181L, 137L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 31L, 58L, 219L, 3L, 112L, 6L, 218L,
182L, 138L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 45L, 69L, 219L, 3L, 120L, 6L, 216L,
183L, 139L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 46L, 70L, 220L, 2L, 90L, 6L, 216L, 184L, 141L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 37L, 63L,
219L, 3L, 114L, 6L, 216L, 186L, 142L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 39L, 65L, 220L, 3L, 100L, 6L, 216L, 187L, 143L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 21L, 81L, 220L,
2L, 89L, 6L, 217L, 188L, 144L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 22L, 82L, 220L, 3L, 106L, 6L, 217L, 189L, 145L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 33L, 59L, 219L,
3L, 110L, 5L, 216L, 190L, 146L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 44L, 68L, 220L, 3L, 99L, 5L, 216L, 191L, 147L, 51L,
51L, 51L, 51L, 51L, 50L, 73L, 220L, 3L, 91L, 5L, 218L, 192L,
148L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 10L, 75L, 219L, 2L, 115L, 5L, 218L, 193L, 149L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 38L, 64L, 220L, 3L, 124L, 5L, 218L, 194L, 150L, 51L,
51L, 51L, 51L, 51L, 51L, 14L, 76L, 220L, 3L, 94L, 5L, 216L, 195L,
152L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 15L, 77L, 219L, 3L, 118L, 5L, 218L, 197L, 153L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 18L, 79L, 219L, 3L, 122L, 5L, 216L, 198L, 154L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 34L, 60L, 220L, 3L, 119L, 7L, 216L, 199L, 155L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 42L, 67L, 220L,
3L, 108L, 7L, 218L, 200L, 51L, 156L, 51L, 51L, 51L, 51L, 51L,
43L, 68L, 219L, 3L, 96L, 7L, 216L, 201L, 157L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 19L, 80L, 219L,
3L, 123L, 7L, 218L, 202L, 158L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 12L, 76L, 219L, 3L, 111L, 7L, 217L, 203L, 159L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 13L, 76L, 220L,
3L, 113L, 7L, 217L, 204L, 160L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 16L, 78L, 220L, 2L, 104L, 7L, 216L, 205L, 161L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 17L, 79L, 219L,
3L, 109L, 7L, 216L, 206L, 163L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 23L, 54L, 219L, 3L, 105L, 7L, 216L, 208L, 51L, 164L,
51L, 51L, 51L, 51L, 51L, 24L, 54L, 220L, 3L, 92L, 7L, 217L, 209L,
165L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 47L, 70L,
220L, 3L, 87L, 7L, 217L, 210L, 166L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L), .Label = c("36=32mod4", "correct_0",
"correct_1", "difficulty_Easy", "difficulty_Hard", "difficulty_Intermediate",
"difficulty_Very", "id_1058", "id_10975", "id_11207", "id_1129",
"id_12052", "id_12069", "id_12131", "id_12453", "id_13285", "id_13741",
"id_13817", "id_14467", "id_14596", "id_14907", "id_15262", "id_1544",
"id_1555", "id_15661", "id_15684", "id_15693", "id_1685", "id_2295",
"id_2479", "id_2820", "id_313", "id_3645", "id_3985", "id_4333",
"id_4541", "id_5249", "id_5426", "id_5684", "id_5756", "id_6016",
"id_6326", "id_7019", "id_7064", "id_7885", "id_8660", "id_8728",
"id_9028", "id_9263", "id_9419", "L", "modulo_26", "modulo_36",
"modulo_40", "modulo_42", "modulo_46", "modulo_47", "modulo_50",
"modulo_55", "modulo_57", "modulo_58", "modulo_59", "modulo_63",
"modulo_64", "modulo_65", "modulo_66", "modulo_68", "modulo_71",
"modulo_74", "modulo_77", "modulo_78", "modulo_79", "modulo_80",
"modulo_85", "modulo_86", "modulo_89", "modulo_90", "modulo_93",
"modulo_94", "modulo_96", "modulo_97", "modulo_98", "modulo_99",
"RT_10590", "RT_1367", "RT_14182", "RT_15412", "RT_1550", "RT_17151",
"RT_17302", "RT_1736", "RT_1891", "RT_2002", "RT_2227", "RT_2241",
"RT_2432", "RT_2510", "RT_2624", "RT_2660", "RT_2840", "RT_2956",
"RT_2984", "RT_3029", "RT_3154", "RT_3273", "RT_3283", "RT_3727",
"RT_3900", "RT_4493", "RT_4544", "RT_4840", "RT_5095", "RT_5368",
"RT_5583", "RT_5618", "RT_6009", "RT_6385", "RT_6423", "RT_6489",
"RT_6689", "RT_7471", "RT_7669", "RT_7697", "RT_8156", "RT_8752",
"RT_8784", "start_consigne", "start_trial_0", "start_trial_1",
"start_trial_10", "start_trial_11", "start_trial_12", "start_trial_13",
"start_trial_14", "start_trial_15", "start_trial_16", "start_trial_17",
"start_trial_18", "start_trial_19", "start_trial_2", "start_trial_20",
"start_trial_21", "start_trial_22", "start_trial_23", "start_trial_24",
"start_trial_25", "start_trial_26", "start_trial_27", "start_trial_28",
"start_trial_29", "start_trial_3", "start_trial_30", "start_trial_31",
"start_trial_32", "start_trial_33", "start_trial_34", "start_trial_35",
"start_trial_36", "start_trial_37", "start_trial_38", "start_trial_39",
"start_trial_4", "start_trial_40", "start_trial_41", "start_trial_42",
"start_trial_43", "start_trial_5", "start_trial_6", "start_trial_7",
"start_trial_8", "start_trial_9", "stop_consigne", "stop_trial_0",
"stop_trial_1", "stop_trial_10", "stop_trial_11", "stop_trial_12",
"stop_trial_13", "stop_trial_14", "stop_trial_15", "stop_trial_16",
"stop_trial_17", "stop_trial_18", "stop_trial_19", "stop_trial_2",
"stop_trial_20", "stop_trial_21", "stop_trial_22", "stop_trial_23",
"stop_trial_24", "stop_trial_25", "stop_trial_26", "stop_trial_27",
"stop_trial_28", "stop_trial_29", "stop_trial_3", "stop_trial_30",
"stop_trial_31", "stop_trial_32", "stop_trial_33", "stop_trial_34",
"stop_trial_35", "stop_trial_36", "stop_trial_37", "stop_trial_38",
"stop_trial_39", "stop_trial_4", "stop_trial_40", "stop_trial_41",
"stop_trial_42", "stop_trial_5", "stop_trial_6", "stop_trial_7",
"stop_trial_8", "stop_trial_9", "strat_1", "strat_2", "strat_4",
"val_0", "val_1"), class = "factor"), PS = c(NA, 904L, 906L,
838L, 805L, 789L, 797L, 876L, 924L, 928L, 964L, 957L, 935L, 861L,
834L, 856L, 846L, 811L, 825L, 869L, 904L, 936L, 969L, 965L, 1016L,
1018L, 1030L, 1015L, 999L, 987L, 1017L, 1064L, 1080L, 1061L,
1075L, 1046L, 1005L, 1014L, 1023L, 1040L, 1051L, 1046L, 1010L,
971L, 994L, 1071L, 1082L, 1120L, 1119L, 1044L, 1023L, 978L, 947L,
925L, 900L, 940L, NA, 963L, NA, 995L, 1013L, 1046L, 1005L, 1013L,
1043L, 1146L, 1205L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1306L,
1334L, 1285L, 1297L, 1257L, 1206L, 1206L, 1256L, 1252L, 1189L,
1254L, 1214L, 1203L, 1207L, 1263L, 1224L, 1235L, 1258L, 1210L,
1186L, 1201L, 1271L, 1246L, 1274L, 1337L, 1325L, 1551L, 1733L,
1812L, 1568L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1272L, 1218L,
1227L, 1165L, 1145L, 1192L, 1199L, 1208L, 1248L, 1280L, 1224L,
NA, NA, NA, NA, NA, NA, NA, NA, 1220L, NA, 1229L, 1250L, 1372L,
1102L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1141L, 1163L, 1146L,
1129L, 1190L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1182L, 1152L,
1134L, 1179L, 1178L, 1267L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1272L, 1186L, 1164L, 1173L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1265L, 1191L, 1109L, 1150L, 1125L, 1090L, 1139L, 1205L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1277L, 1164L, 1122L, 1113L, 1115L,
1121L, 1168L, NA, NA, NA, NA, NA, NA, NA, NA, 1235L, NA, 1207L,
1164L, 1145L, 1177L, 1242L, 1224L, 1281L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1234L, 1232L, 1204L, 1198L, 1108L, 1131L, 1220L,
1228L, 1227L, 1231L, 1299L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1211L, 1266L, 1294L, 1292L, 1129L, 1182L, 1175L, 1211L, 1233L,
1206L, 1185L, 1307L, 1209L, 1206L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1245L, 1264L, 1283L, 1246L, 1290L, 1344L, 1311L, 1267L,
1201L, 1188L, 1164L, 1218L, 1188L, 1156L, 1144L, 1121L, 1145L,
1176L, 1155L, 1103L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1173L,
1223L, 1218L, 1170L, 1120L, 1084L, 1096L, 1092L, 985L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1043L, 1092L, 1090L, 1126L, 1099L,
1125L, 1175L, 1099L, 1102L, 1188L, 1215L, 1225L, 1197L, 1268L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1292L, 1338L, 1322L, 1284L,
1296L, 1273L, 1251L, 1216L, 1205L, 1200L, 1165L, 1097L, 1132L,
1209L, 1243L, 1295L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1288L,
1286L, 1243L, 1245L, 1215L, 1213L, 1215L, 1283L, 1280L, 1275L,
1334L, 1301L, 1205L, 1215L, 1267L, 1245L, 1203L, 1071L, 1113L,
1160L, 1211L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1243L, 1249L,
1268L, 1266L, 1299L, 1363L, 1215L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 938L, 831L, 929L, 999L, 1033L, 1090L, 1092L, 1094L, 1139L,
1144L, 1225L, 1203L, 1199L, 1261L, 1221L, 1230L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, 1291L, 1308L, 1270L, 1250L, 1276L, 1226L,
1197L, 1201L, 1213L, 1195L, 1202L, 1201L, 1194L, 1192L, 1190L,
1206L, 1244L, 1203L, 1228L, 1239L, 1218L, 1218L, 1217L, 1218L,
1202L, 1224L, 1177L, 1134L, 1134L, 1152L, 1159L, 1162L, 1168L,
1107L, 1175L, 1200L, 1173L, 1203L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1266L, 1278L, 1227L, 1188L, 1184L, 1178L, 1167L, 1194L,
1131L, 1166L, 1203L, 1211L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1223L, 1226L, 1218L, 1208L, 1142L, 1105L, 1122L, 1156L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1118L, 1133L, 1150L, 1115L, 1070L,
1078L, 1145L, 1156L, 1175L, 1172L, 1129L, 1134L, 1089L, 1144L,
1171L, 1179L, 1195L, 1194L, 1231L, 1275L, 1250L, 1273L, 1268L,
1221L, 1245L, 1211L, 1195L, 1197L, 1194L, 1140L, 1168L, 1220L,
1197L, 1191L, 1240L, 1288L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1339L, 1327L, 1324L, 1320L, 1242L, 1231L, 1253L, 1255L, 1268L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1297L, 1303L, 1282L, 1252L,
1200L, 1202L, 1191L, 1177L, 1220L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1221L, 1224L, 1203L, 1162L, 1175L, 1187L, 1184L, 1165L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1200L, 1225L, 1200L, 1205L,
1219L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1269L, 1209L, 1161L,
1171L, 1165L, 1140L, 1120L, 1127L, 1076L, 1081L, 1081L, 1114L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1181L, 1186L, 1189L, 1200L,
1179L, 1186L, 1171L, 1134L, 1012L, 1004L, 1134L, 1090L, 1146L,
1222L, 1309L, 1334L, 1354L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1240L, 1121L, 1101L, 1104L, 1142L, 1157L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1197L, 1264L, 1217L, 1181L, 1173L, 1160L, 1147L,
1174L, 1188L, 1183L, 1162L, 1188L, 1273L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1303L, 1335L, 1346L, 1284L, 1227L, 1245L, 1295L,
1291L, 1284L, 1125L, 1176L, 1214L, 1206L, 1216L, 1232L, 1234L,
1268L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1326L, 1284L, 1265L,
1237L, 1206L, 1212L, 1197L, 1181L, 1216L, 1222L, 1205L, 1148L,
1163L, 1154L, 1138L, 1146L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1250L, 1229L, 1209L, 1199L, 1165L, 1191L, 1145L, 1130L, 1116L,
NA, NA, NA, NA, NA, NA, NA, NA, 1101L, NA, 1113L, 1126L, 1138L,
1160L, 1128L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1155L, 1132L,
1122L, 1146L, 1145L, 1146L, 1171L, 1103L, 1170L, 1136L, 1177L,
1108L, 1106L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1175L, 1192L,
1129L, 1163L, 1187L, 1177L, 1162L, 1184L, 1129L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, 1221L, 1113L, 1089L, 1099L, 1022L, 995L,
947L, 1012L, 1065L, 1114L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1163L, 1094L, 1098L, 1139L, 1130L, 1117L, 1087L, 1084L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1137L, 1145L, 1130L, 1105L, 1123L,
1112L, 1048L, 1055L, 1078L, 1147L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1207L, 1164L, 1169L, 1188L, 1189L, 1140L, 1099L, 1178L,
NA, NA, NA, NA, NA, NA, NA, NA, 1208L, NA, 1258L, 1207L, 1158L,
1140L, 1099L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1123L, 1083L,
1043L, 1066L, 1082L, 1049L, 1040L, 1090L, 1112L, 1069L, 1079L,
1061L, 1029L, 1032L, 1046L, 1170L, 1197L, 956L, 941L, 1076L,
1136L, 1208L, 1213L, 1207L, 1186L, 1225L, 1222L, 1232L, 1169L,
1102L, 1144L, 1178L, 1218L, 1211L, 1229L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1255L, 1260L, 1236L, 1271L, 1312L, 1346L, 1272L,
1171L, 1192L, 1235L, 1296L), Modulo =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od4", "59=57mod2",
"63=33mod4", "64=24mod8", "65=35mod6", "65=51mod6", "66=61mod6",
"68=26mod6", "71=21mod6", "71=31mod4", "74=53mod8", "77=53mod4",
"77=69mod2", "78=75mod4", "79=67mod6", "80=40mod4", "85=65mod4",
"86=50mod8", "89=32mod2", "89=35mod2", "89=49mod4", "90=50mod6",
"93=13mod8", "94=43mod4", "94=61mod4", "96=54mod4", "96=82mod6",
"97=75mod2", "98=76mod2", "99=85mod8", "99=91mod8", "99=93mod6"
), class = "factor")), class = "data.frame", row.names = c(NA,
-997L))
#Brian here is a sample of my dataset:
1 MSG start_consigne NA
2 EFI L 904
3 EFI L 906
4 EFI L 838
5 EFI L 805
6 EFI L 789
7 EFI L 797
8 EFI L 876
9 EFI L 924
10 EFI L 928
11 EFI L 964
12 EFI L 957
13 EFI L 935
14 EFI L 861
15 EFI L 834
16 EFI L 856
17 EFI L 846
18 EFI L 811
19 EFI L 825
20 EFI L 869
21 EFI L 904
22 EFI L 936
23 EFI L 969
24 EFI L 965
25 EFI L 1016
26 EFI L 1018
27 EFI L 1030
28 EFI L 1015
29 EFI L 999
30 EFI L 987
31 EFI L 1017
32 EFI L 1064
33 EFI L 1080
34 EFI L 1061
35 EFI L 1075
36 EFI L 1046
37 EFI L 1005
38 EFI L 1014
39 EFI L 1023
40 EFI L 1040
41 EFI L 1051
42 EFI L 1046
43 EFI L 1010
44 EFI L 971
45 EFI L 994
46 EFI L 1071
47 EFI L 1082
48 EFI L 1120
49 EFI L 1119
50 EFI L 1044
51 EFI L 1023
52 EFI L 978
53 EFI L 947
54 EFI L 925
55 EFI L 900
56 EFI L 940
57 MSG stop_consigne NA
58 EFI L 963
59 MSG start_trial_0 NA
60 EFI L 995
61 EFI L 1013
62 EFI L 1046
63 EFI L 1005
64 EFI L 1013
65 EFI L 1043
66 EFI L 1146
67 EFI L 1205
68 MSG id_1129 NA
69 MSG 36=32mod4 NA 36=32mod4
70 MSG val_1 NA
71 MSG correct_1 NA
72 MSG RT_2241 NA
73 MSG difficulty_Very NA
74 MSG strat_4 NA
75 MSG stop_trial_0 NA
76 MSG start_trial_1 NA
77 EFI L 1306
78 EFI L 1334
79 EFI L 1285
80 EFI L 1297
81 EFI L 1257
82 EFI L 1206
83 EFI L 1206
84 EFI L 1256
85 EFI L 1252
86 EFI L 1189
87 EFI L 1254
88 EFI L 1214
89 EFI L 1203
90 EFI L 1207
91 EFI L 1263
92 EFI L 1224
93 EFI L 1235
94 EFI L 1258
95 EFI L 1210
96 EFI L 1186
97 EFI L 1201
98 EFI L 1271
99 EFI L 1246
100 EFI L 1274
101 EFI L 1337
102 EFI L 1325
103 EFI L 1551
104 EFI L 1733
105 EFI L 1812
106 EFI L 1568
107 MSG id_4333 NA
108 MSG modulo_58 NA 58=52mod4
109 MSG val_0 NA
110 MSG correct_1 NA
111 MSG RT_14182 NA
112 MSG difficulty_Very NA
113 MSG strat_4 NA
114 MSG stop_trial_1 NA
115 MSG start_trial_2 NA
116 EFI L 1272
117 EFI L 1218
118 EFI L 1227
119 EFI L 1165
120 EFI L 1145
121 EFI L 1192
122 EFI L 1199
123 EFI L 1208
124 EFI L 1248
125 EFI L 1280
126 EFI L 1224
127 MSG id_6016 NA
128 MSG modulo_66 NA 66=61mod6
129 MSG val_0 NA
130 MSG correct_1 NA
131 MSG RT_3727 NA
132 MSG difficulty_Very NA
133 MSG strat_1 NA
134 MSG stop_trial_2 NA
135 EFI L 1220
136 MSG start_trial_3 NA
137 EFI L 1229
138 EFI L 1250
139 EFI L 1372
140 EFI L 1102
141 MSG id_15693 NA
142 MSG modulo_99 NA 99=93mod6
143 MSG val_1 NA
144 MSG correct_1 NA
145 MSG RT_2624 NA
146 MSG difficulty_Very NA
147 MSG strat_1 NA
148 MSG stop_trial_3 NA
149 MSG start_trial_4 NA````
structure(list(Event = structure(c(2L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,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51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 172L, 51L, 128L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
11L, 1L, 220L, 3L, 95L, 7L, 218L, 173L, 129L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 35L, 61L, 219L, 3L, 86L, 7L, 218L, 174L, 140L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 41L, 66L, 219L,
3L, 107L, 7L, 216L, 185L, 51L, 151L, 51L, 51L, 51L, 51L, 27L,
83L, 220L, 3L, 98L, 7L, 216L, 196L, 162L, 51L, 51L, 51L, 51L,
51L, 30L, 57L, 219L, 3L, 88L, 7L, 217L, 207L, 167L, 51L, 51L,
51L, 51L, 51L, 51L, 36L, 62L, 220L, 3L, 93L, 7L, 217L, 211L,
168L, 51L, 51L, 51L, 51L, 48L, 71L, 219L, 3L, 85L, 7L, 216L,
212L, 169L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 26L, 83L,
220L, 3L, 102L, 7L, 216L, 213L, 170L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 29L, 56L, 220L, 3L, 101L, 4L, 218L, 214L, 51L, 171L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 49L, 72L, 220L, 2L, 103L,
4L, 216L, 215L, 130L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 20L, 80L, 219L, 3L, 116L, 4L, 218L, 175L, 131L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 25L, 83L, 219L, 3L, 125L, 4L, 216L, 176L, 132L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 32L, 52L, 219L, 3L, 126L, 4L, 218L,
177L, 133L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 8L,
53L, 220L, 3L, 97L, 4L, 218L, 178L, 134L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 40L, 65L, 219L,
3L, 117L, 4L, 216L, 179L, 135L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 9L, 74L, 220L,
3L, 121L, 4L, 216L, 180L, 136L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 28L, 55L, 220L, 3L, 84L, 6L, 218L, 181L, 137L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 31L, 58L, 219L, 3L, 112L, 6L, 218L,
182L, 138L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 45L, 69L, 219L, 3L, 120L, 6L, 216L,
183L, 139L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 46L, 70L, 220L, 2L, 90L, 6L, 216L, 184L, 141L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 37L, 63L,
219L, 3L, 114L, 6L, 216L, 186L, 142L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 39L, 65L, 220L, 3L, 100L, 6L, 216L, 187L, 143L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 21L, 81L, 220L,
2L, 89L, 6L, 217L, 188L, 144L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 22L, 82L, 220L, 3L, 106L, 6L, 217L, 189L, 145L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 33L, 59L, 219L,
3L, 110L, 5L, 216L, 190L, 146L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 44L, 68L, 220L, 3L, 99L, 5L, 216L, 191L, 147L, 51L,
51L, 51L, 51L, 51L, 50L, 73L, 220L, 3L, 91L, 5L, 218L, 192L,
148L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 10L, 75L, 219L, 2L, 115L, 5L, 218L, 193L, 149L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 38L, 64L, 220L, 3L, 124L, 5L, 218L, 194L, 150L, 51L,
51L, 51L, 51L, 51L, 51L, 14L, 76L, 220L, 3L, 94L, 5L, 216L, 195L,
152L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 15L, 77L, 219L, 3L, 118L, 5L, 218L, 197L, 153L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 18L, 79L, 219L, 3L, 122L, 5L, 216L, 198L, 154L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 34L, 60L, 220L, 3L, 119L, 7L, 216L, 199L, 155L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 42L, 67L, 220L,
3L, 108L, 7L, 218L, 200L, 51L, 156L, 51L, 51L, 51L, 51L, 51L,
43L, 68L, 219L, 3L, 96L, 7L, 216L, 201L, 157L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 19L, 80L, 219L,
3L, 123L, 7L, 218L, 202L, 158L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 12L, 76L, 219L, 3L, 111L, 7L, 217L, 203L, 159L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 13L, 76L, 220L,
3L, 113L, 7L, 217L, 204L, 160L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 16L, 78L, 220L, 2L, 104L, 7L, 216L, 205L, 161L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 17L, 79L, 219L,
3L, 109L, 7L, 216L, 206L, 163L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 23L, 54L, 219L, 3L, 105L, 7L, 216L, 208L, 51L, 164L,
51L, 51L, 51L, 51L, 51L, 24L, 54L, 220L, 3L, 92L, 7L, 217L, 209L,
165L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 47L, 70L,
220L, 3L, 87L, 7L, 217L, 210L, 166L, 51L, 51L, 51L, 51L, 51L,
51L, 51L, 51L, 51L, 51L, 51L), .Label = c("36=32mod4", "correct_0",
"correct_1", "difficulty_Easy", "difficulty_Hard", "difficulty_Intermediate",
"difficulty_Very", "id_1058", "id_10975", "id_11207", "id_1129",
"id_12052", "id_12069", "id_12131", "id_12453", "id_13285", "id_13741",
"id_13817", "id_14467", "id_14596", "id_14907", "id_15262", "id_1544",
"id_1555", "id_15661", "id_15684", "id_15693", "id_1685", "id_2295",
"id_2479", "id_2820", "id_313", "id_3645", "id_3985", "id_4333",
"id_4541", "id_5249", "id_5426", "id_5684", "id_5756", "id_6016",
"id_6326", "id_7019", "id_7064", "id_7885", "id_8660", "id_8728",
"id_9028", "id_9263", "id_9419", "L", "modulo_26", "modulo_36",
"modulo_40", "modulo_42", "modulo_46", "modulo_47", "modulo_50",
"modulo_55", "modulo_57", "modulo_58", "modulo_59", "modulo_63",
"modulo_64", "modulo_65", "modulo_66", "modulo_68", "modulo_71",
"modulo_74", "modulo_77", "modulo_78", "modulo_79", "modulo_80",
"modulo_85", "modulo_86", "modulo_89", "modulo_90", "modulo_93",
"modulo_94", "modulo_96", "modulo_97", "modulo_98", "modulo_99",
"RT_10590", "RT_1367", "RT_14182", "RT_15412", "RT_1550", "RT_17151",
"RT_17302", "RT_1736", "RT_1891", "RT_2002", "RT_2227", "RT_2241",
"RT_2432", "RT_2510", "RT_2624", "RT_2660", "RT_2840", "RT_2956",
"RT_2984", "RT_3029", "RT_3154", "RT_3273", "RT_3283", "RT_3727",
"RT_3900", "RT_4493", "RT_4544", "RT_4840", "RT_5095", "RT_5368",
"RT_5583", "RT_5618", "RT_6009", "RT_6385", "RT_6423", "RT_6489",
"RT_6689", "RT_7471", "RT_7669", "RT_7697", "RT_8156", "RT_8752",
"RT_8784", "start_consigne", "start_trial_0", "start_trial_1",
"start_trial_10", "start_trial_11", "start_trial_12", "start_trial_13",
"start_trial_14", "start_trial_15", "start_trial_16", "start_trial_17",
"start_trial_18", "start_trial_19", "start_trial_2", "start_trial_20",
"start_trial_21", "start_trial_22", "start_trial_23", "start_trial_24",
"start_trial_25", "start_trial_26", "start_trial_27", "start_trial_28",
"start_trial_29", "start_trial_3", "start_trial_30", "start_trial_31",
"start_trial_32", "start_trial_33", "start_trial_34", "start_trial_35",
"start_trial_36", "start_trial_37", "start_trial_38", "start_trial_39",
"start_trial_4", "start_trial_40", "start_trial_41", "start_trial_42",
"start_trial_43", "start_trial_5", "start_trial_6", "start_trial_7",
"start_trial_8", "start_trial_9", "stop_consigne", "stop_trial_0",
"stop_trial_1", "stop_trial_10", "stop_trial_11", "stop_trial_12",
"stop_trial_13", "stop_trial_14", "stop_trial_15", "stop_trial_16",
"stop_trial_17", "stop_trial_18", "stop_trial_19", "stop_trial_2",
"stop_trial_20", "stop_trial_21", "stop_trial_22", "stop_trial_23",
"stop_trial_24", "stop_trial_25", "stop_trial_26", "stop_trial_27",
"stop_trial_28", "stop_trial_29", "stop_trial_3", "stop_trial_30",
"stop_trial_31", "stop_trial_32", "stop_trial_33", "stop_trial_34",
"stop_trial_35", "stop_trial_36", "stop_trial_37", "stop_trial_38",
"stop_trial_39", "stop_trial_4", "stop_trial_40", "stop_trial_41",
"stop_trial_42", "stop_trial_5", "stop_trial_6", "stop_trial_7",
"stop_trial_8", "stop_trial_9", "strat_1", "strat_2", "strat_4",
"val_0", "val_1"), class = "factor"), PS = c(NA, 904L, 906L,
838L, 805L, 789L, 797L, 876L, 924L, 928L, 964L, 957L, 935L, 861L,
834L, 856L, 846L, 811L, 825L, 869L, 904L, 936L, 969L, 965L, 1016L,
1018L, 1030L, 1015L, 999L, 987L, 1017L, 1064L, 1080L, 1061L,
1075L, 1046L, 1005L, 1014L, 1023L, 1040L, 1051L, 1046L, 1010L,
971L, 994L, 1071L, 1082L, 1120L, 1119L, 1044L, 1023L, 978L, 947L,
925L, 900L, 940L, NA, 963L, NA, 995L, 1013L, 1046L, 1005L, 1013L,
1043L, 1146L, 1205L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1306L,
1334L, 1285L, 1297L, 1257L, 1206L, 1206L, 1256L, 1252L, 1189L,
1254L, 1214L, 1203L, 1207L, 1263L, 1224L, 1235L, 1258L, 1210L,
1186L, 1201L, 1271L, 1246L, 1274L, 1337L, 1325L, 1551L, 1733L,
1812L, 1568L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1272L, 1218L,
1227L, 1165L, 1145L, 1192L, 1199L, 1208L, 1248L, 1280L, 1224L,
NA, NA, NA, NA, NA, NA, NA, NA, 1220L, NA, 1229L, 1250L, 1372L,
1102L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1141L, 1163L, 1146L,
1129L, 1190L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1182L, 1152L,
1134L, 1179L, 1178L, 1267L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1272L, 1186L, 1164L, 1173L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1265L, 1191L, 1109L, 1150L, 1125L, 1090L, 1139L, 1205L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1277L, 1164L, 1122L, 1113L, 1115L,
1121L, 1168L, NA, NA, NA, NA, NA, NA, NA, NA, 1235L, NA, 1207L,
1164L, 1145L, 1177L, 1242L, 1224L, 1281L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1234L, 1232L, 1204L, 1198L, 1108L, 1131L, 1220L,
1228L, 1227L, 1231L, 1299L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1211L, 1266L, 1294L, 1292L, 1129L, 1182L, 1175L, 1211L, 1233L,
1206L, 1185L, 1307L, 1209L, 1206L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1245L, 1264L, 1283L, 1246L, 1290L, 1344L, 1311L, 1267L,
1201L, 1188L, 1164L, 1218L, 1188L, 1156L, 1144L, 1121L, 1145L,
1176L, 1155L, 1103L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1173L,
1223L, 1218L, 1170L, 1120L, 1084L, 1096L, 1092L, 985L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1043L, 1092L, 1090L, 1126L, 1099L,
1125L, 1175L, 1099L, 1102L, 1188L, 1215L, 1225L, 1197L, 1268L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1292L, 1338L, 1322L, 1284L,
1296L, 1273L, 1251L, 1216L, 1205L, 1200L, 1165L, 1097L, 1132L,
1209L, 1243L, 1295L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1288L,
1286L, 1243L, 1245L, 1215L, 1213L, 1215L, 1283L, 1280L, 1275L,
1334L, 1301L, 1205L, 1215L, 1267L, 1245L, 1203L, 1071L, 1113L,
1160L, 1211L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1243L, 1249L,
1268L, 1266L, 1299L, 1363L, 1215L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 938L, 831L, 929L, 999L, 1033L, 1090L, 1092L, 1094L, 1139L,
1144L, 1225L, 1203L, 1199L, 1261L, 1221L, 1230L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, 1291L, 1308L, 1270L, 1250L, 1276L, 1226L,
1197L, 1201L, 1213L, 1195L, 1202L, 1201L, 1194L, 1192L, 1190L,
1206L, 1244L, 1203L, 1228L, 1239L, 1218L, 1218L, 1217L, 1218L,
1202L, 1224L, 1177L, 1134L, 1134L, 1152L, 1159L, 1162L, 1168L,
1107L, 1175L, 1200L, 1173L, 1203L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1266L, 1278L, 1227L, 1188L, 1184L, 1178L, 1167L, 1194L,
1131L, 1166L, 1203L, 1211L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1223L, 1226L, 1218L, 1208L, 1142L, 1105L, 1122L, 1156L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1118L, 1133L, 1150L, 1115L, 1070L,
1078L, 1145L, 1156L, 1175L, 1172L, 1129L, 1134L, 1089L, 1144L,
1171L, 1179L, 1195L, 1194L, 1231L, 1275L, 1250L, 1273L, 1268L,
1221L, 1245L, 1211L, 1195L, 1197L, 1194L, 1140L, 1168L, 1220L,
1197L, 1191L, 1240L, 1288L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1339L, 1327L, 1324L, 1320L, 1242L, 1231L, 1253L, 1255L, 1268L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1297L, 1303L, 1282L, 1252L,
1200L, 1202L, 1191L, 1177L, 1220L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1221L, 1224L, 1203L, 1162L, 1175L, 1187L, 1184L, 1165L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1200L, 1225L, 1200L, 1205L,
1219L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1269L, 1209L, 1161L,
1171L, 1165L, 1140L, 1120L, 1127L, 1076L, 1081L, 1081L, 1114L,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 1181L, 1186L, 1189L, 1200L,
1179L, 1186L, 1171L, 1134L, 1012L, 1004L, 1134L, 1090L, 1146L,
1222L, 1309L, 1334L, 1354L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1240L, 1121L, 1101L, 1104L, 1142L, 1157L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1197L, 1264L, 1217L, 1181L, 1173L, 1160L, 1147L,
1174L, 1188L, 1183L, 1162L, 1188L, 1273L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1303L, 1335L, 1346L, 1284L, 1227L, 1245L, 1295L,
1291L, 1284L, 1125L, 1176L, 1214L, 1206L, 1216L, 1232L, 1234L,
1268L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1326L, 1284L, 1265L,
1237L, 1206L, 1212L, 1197L, 1181L, 1216L, 1222L, 1205L, 1148L,
1163L, 1154L, 1138L, 1146L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1250L, 1229L, 1209L, 1199L, 1165L, 1191L, 1145L, 1130L, 1116L,
NA, NA, NA, NA, NA, NA, NA, NA, 1101L, NA, 1113L, 1126L, 1138L,
1160L, 1128L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1155L, 1132L,
1122L, 1146L, 1145L, 1146L, 1171L, 1103L, 1170L, 1136L, 1177L,
1108L, 1106L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1175L, 1192L,
1129L, 1163L, 1187L, 1177L, 1162L, 1184L, 1129L, NA, NA, NA,
NA, NA, NA, NA, NA, NA, 1221L, 1113L, 1089L, 1099L, 1022L, 995L,
947L, 1012L, 1065L, 1114L, NA, NA, NA, NA, NA, NA, NA, NA, NA,
1163L, 1094L, 1098L, 1139L, 1130L, 1117L, 1087L, 1084L, NA, NA,
NA, NA, NA, NA, NA, NA, NA, 1137L, 1145L, 1130L, 1105L, 1123L,
1112L, 1048L, 1055L, 1078L, 1147L, NA, NA, NA, NA, NA, NA, NA,
NA, NA, 1207L, 1164L, 1169L, 1188L, 1189L, 1140L, 1099L, 1178L,
NA, NA, NA, NA, NA, NA, NA, NA, 1208L, NA, 1258L, 1207L, 1158L,
1140L, 1099L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 1123L, 1083L,
1043L, 1066L, 1082L, 1049L, 1040L, 1090L, 1112L, 1069L, 1079L,
1061L, 1029L, 1032L, 1046L, 1170L, 1197L, 956L, 941L, 1076L,
1136L, 1208L, 1213L, 1207L, 1186L, 1225L, 1222L, 1232L, 1169L,
1102L, 1144L, 1178L, 1218L, 1211L, 1229L, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 1255L, 1260L, 1236L, 1271L, 1312L, 1346L, 1272L,
1171L, 1192L, 1235L, 1296L), Modulo = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 13L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 19L, 1L,
1L, 1L, 1L, 1L, 1L,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 36L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 25L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c(" ", "26=12mod6", "36=16mod4", "36=32mod4",
"40=33mod8", "40=36mod2", "42=12mod6", "46=34mod6", "47=44mod2",
"50=20mod4", "55=20mod4", "57=15mod6", "58=52mod4", "59=57mod2",
"63=33mod4", "64=24mod8", "65=35mod6", "65=51mod6", "66=61mod6",
"68=26mod6", "71=21mod6", "71=31mod4", "74=53mod8", "77=53mod4",
"77=69mod2", "78=75mod4", "79=67mod6", "80=40mod4", "85=65mod4",
"86=50mod8", "89=32mod2", "89=35mod2", "89=49mod4", "90=50mod6",
"93=13mod8", "94=43mod4", "94=61mod4", "96=54mod4", "96=82mod6",
"97=75mod2", "98=76mod2", "99=85mod8", "99=91mod8", "99=93mod6"
), class = "factor")), class = "data.frame", row.names = c(NA,
-997L))````
Brian has offered a perfect approach to your problem. My approach was slightly different, yet with similar results. For the sake of completion and/or variety i am going to post it though.
My way of thinking is as follows:
You first read in your file and pass it into a dataframe df
library(dplyr) # load the libraries we are going to be using first
library(tidyr)
library(zoo)
df <- read.csv('~/Desktop/test', sep = ';', header = T) # I named your .txt file test here and put it on my Desktop
>df
Event Info Pupil.size
1 Message Start_trial_0 NA
2 Fixation L 1020
3 Fixation L 1200
4 Fixation L 980
5 Fixation L 990
6 Fixation L 1003
7 Message Trial_0 NA
8 Message ACC_0 NA
9 Message RT_850 NA
10 Message Stop_trial_0 NA
11 Message Start_trial_1 NA
12 Fixation L 1023
13 Fixation L 1020
14 Fixation L 997
15 Fixation L 1123
16 Message Trial_1 NA
17 Message ACC_1 NA
18 Message RT_920 NA
19 Message Stop_trial_1 NA
20 Message Strat_trial_2 NA
Then we create a new column, named trial where for every row on Info that has the trial info (the Start and Stop in this case), we pass the corresponding trial, otherwise we fill with NA, as such:
Option 1 (original file data):
df <- df %>% mutate(trial=ifelse(Event=='Message'&grepl('trial', df$Info), gsub('.*_(trial_\\d)$', '\\1', df$Info), NA))
Event Info Pupil.size trial
1 Message Start_trial_0 NA trial_0
2 Fixation L 1020 <NA>
3 Fixation L 1200 <NA>
4 Fixation L 980 <NA>
5 Fixation L 990 <NA>
6 Fixation L 1003 <NA>
7 Message Trial_0 NA <NA>
8 Message ACC_0 NA <NA>
9 Message RT_850 NA <NA>
10 Message Stop_trial_0 NA trial_0
11 Message Start_trial_1 NA trial_1
12 Fixation L 1023 <NA>
13 Fixation L 1020 <NA>
14 Fixation L 997 <NA>
15 Fixation L 1123 <NA>
16 Message Trial_1 NA <NA>
17 Message ACC_1 NA <NA>
18 Message RT_920 NA <NA>
19 Message Stop_trial_1 NA trial_1
20 Message Strat_trial_2 NA trial_2
Option 2 (new input file - keep in mind this preserves the in-between trial data that you might want to get rid of):
df <- df %>% mutate(trial=ifelse(Event=='MSG'&grepl('trial', df$Info), gsub('.*_(trial_\\d)$', '\\1', df$Info),
ifelse(Event=='MSG'&grepl('consigne', df$Info), gsub('.*_(consigne)$', '\\1', df$Info),
NA)))
I am filling with NA since on the next step we want to replace NAs with the earliest previous non NA value (thus assigning the correct trial on every row between the Start-Stop). This can be done with na.locf from the package zoo.
df$trial <- na.locf(df$trial)
> df
Event Info Pupil.size trial
1 Message Start_trial_0 NA trial_0
2 Fixation L 1020 trial_0
3 Fixation L 1200 trial_0
4 Fixation L 980 trial_0
5 Fixation L 990 trial_0
6 Fixation L 1003 trial_0
7 Message Trial_0 NA trial_0
8 Message ACC_0 NA trial_0
9 Message RT_850 NA trial_0
10 Message Stop_trial_0 NA trial_0
11 Message Start_trial_1 NA trial_1
12 Fixation L 1023 trial_1
13 Fixation L 1020 trial_1
14 Fixation L 997 trial_1
15 Fixation L 1123 trial_1
16 Message Trial_1 NA trial_1
17 Message ACC_1 NA trial_1
18 Message RT_920 NA trial_1
19 Message Stop_trial_1 NA trial_1
20 Message Strat_trial_2 NA trial_2
We can now get rid of the rows with Trial "metadata" on the Info column.
df <- df %>% filter(!grepl('[T,t]rial', df$Info))
Next, we need the final "metadata" information per trial, namely ACC and RT information. These information are all within the Info column so we have to pull them out somehow. To do that first, we create two new columns named ACC and RT.
df <- df %>% mutate(ACC=ifelse(grepl('ACC', df$Info), as.character(df$Info), NA),
RT=ifelse(grepl('RT', df$Info), as.character(df$Info), NA))
> df
Event Info Pupil.size trial ACC RT
1 Fixation L 1020 trial_0 <NA> <NA>
2 Fixation L 1200 trial_0 <NA> <NA>
3 Fixation L 980 trial_0 <NA> <NA>
4 Fixation L 990 trial_0 <NA> <NA>
5 Fixation L 1003 trial_0 <NA> <NA>
6 Message ACC_0 NA trial_0 ACC_0 <NA>
7 Message RT_850 NA trial_0 <NA> RT_850
8 Fixation L 1023 trial_1 <NA> <NA>
9 Fixation L 1020 trial_1 <NA> <NA>
10 Fixation L 997 trial_1 <NA> <NA>
11 Fixation L 1123 trial_1 <NA> <NA>
12 Message ACC_1 NA trial_1 ACC_1 <NA>
13 Message RT_920 NA trial_1 <NA> RT_920
We also need to make sure which ACC and RT attributes correspond to each trial. For that purpose we create two new small dataframes via dplyr that give us all the ACC and RT info.
infoACC <- df %>% group_by(trial, Info) %>% summarize() %>% filter(grepl('ACC', Info))
> infoACC
# A tibble: 2 x 2
# Groups: trial [2]
trial Info
<chr> <fct>
1 trial_0 " ACC_0"
2 trial_1 " ACC_1"
infoRT <- df %>% group_by(trial, Info) %>% summarize() %>% filter(grepl('RT', Info))
> infoRT
# A tibble: 2 x 2
# Groups: trial [2]
trial Info
<chr> <fct>
1 trial_0 " RT_850"
2 trial_1 " RT_920"
Then it's just a matter of joining our df and the two new dataframes to get the ACC and RT info in, dropping the additional columns and left-over rows (Message rows)
df <- left_join(left_join(df, infoACC, by='trial'), infoRT, by='trial') %>% select(-ACC, -RT) %>% filter(!Event=='Message')
And wrap this up with fixing up the column names.
colnames(df) <- c('Event', 'Info', 'Pupil.size', 'Trial', 'ACC', 'RT')
> df
Event Info Pupil.size Trial ACC RT
1 Fixation L 1020 trial_0 ACC_0 RT_850
2 Fixation L 1200 trial_0 ACC_0 RT_850
3 Fixation L 980 trial_0 ACC_0 RT_850
4 Fixation L 990 trial_0 ACC_0 RT_850
5 Fixation L 1003 trial_0 ACC_0 RT_850
6 Fixation L 1023 trial_1 ACC_1 RT_920
7 Fixation L 1020 trial_1 ACC_1 RT_920
8 Fixation L 997 trial_1 ACC_1 RT_920
9 Fixation L 1123 trial_1 ACC_1 RT_920
You can now save this as a new .csv or keep it as a dataframe for further operations in R.
I admit its a bit of a more complicated solution, but i wanted to offer my thinking process hoping to show you that there are many ways to approach your problems in R and you can tackle your questions in a stepwise manner.
Hope this helps

How to create a faceted boxplot with the significant differences, and 2 measured variables?

I managed to create a faceted boxplot with my 2 quantitative variables;
I know how to run a kruskal-wallis followed by a Wilcoxon test and show the significant differences with letters in the boxplot but only in a simple boxplot, with one variable and without facet. How can I do ?
(If possible, I would like to put the siginificant differences with letters, I wish I would be able to post the pictures of what I already done but apparently I'm not allowed)
Also, I have another question; Which test does the function stat_function_mean execute ? I tried to use this function, but I don't know how to use it... Here is my code without the test, only the facetted boxplot with my two variables :
Code for my facet boxplot with 2 measured variables ( FF and FM)
dat.m2 <- melt(pheno,id.vars=c("fusion","Genotype","Hormone"),
measure.vars=c('FF','MF'))
dat.m2$fusion<-factor(dat.m2$fusion, levels=c("Control", "CK 20 mg/L", "CK 100 mg/L", "CK 500 mg/L", "GA 20 mg/L", "GA 100 mg/L", "GA 500 mg/L"))
levels(dat.m2$fusion)
ggplot(dat.m2) +
geom_boxplot(aes(x=fusion, y=value, colour=variable))+
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")
Code to add significant differences on the graph, with letters, but with only 1 measured variable (FF), without facet
mymat <-tri.to.squ(pp$p.value)
mymat
myletters <- multcompLetters(mymat,compare="<=",threshold=0.05,Letters=letters)
myletters
myletters_df <- data.frame(fusion=names(myletters$Letters),letter = myletters$Letters )
myletters_df
ggplot(pheno, aes(x=fusion, y=FF, colour=fusion))+
geom_boxplot()+
geom_text(data = myletters_df, aes(label = letter, y = 30 ), colour="black", size=5)+
ylab("Days after sowing")+
xlab("")+
labs(title="Days to female flower production")+
theme(plot.title = element_text(hjust = 0.5))+
> dput(pheno)
structure(list(Genotype = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("F1045",
"FF", "M1585", "M1610"), class = "factor"), X = structure(c(1L,
105L, 116L, 127L, 138L, 149L, 160L, 171L, 182L, 2L, 13L, 24L,
35L, 46L, 57L, 68L, 79L, 90L, 101L, 106L, 107L, 108L, 109L, 110L,
111L, 112L, 113L, 114L, 115L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L,
147L, 148L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L,
172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 183L,
184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 47L, 48L,
49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L,
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 102L, 103L, 104L
), .Label = c("H1", "H10", "H100", "H101", "H102", "H103", "H104",
"H105", "H106", "H107", "H108", "H109", "H11", "H110", "H111",
"H112", "H113", "H114", "H115", "H116", "H117", "H118", "H119",
"H12", "H120", "H121", "H122", "H123", "H124", "H125", "H126",
"H127", "H128", "H129", "H13", "H130", "H131", "H132", "H133",
"H134", "H135", "H136", "H137", "H138", "H139", "H14", "H140",
"H141", "H142", "H143", "H144", "H145", "H146", "H147", "H148",
"H149", "H15", "H150", "H151", "H152", "H153", "H154", "H155",
"H156", "H157", "H158", "H159", "H16", "H160", "H161", "H162",
"H163", "H164", "H165", "H166", "H167", "H168", "H169", "H17",
"H170", "H171", "H172", "H173", "H174", "H175", "H176", "H177",
"H178", "H179", "H18", "H180", "H181", "H182", "H183", "H184",
"H185", "H186", "H187", "H188", "H189", "H19", "H190", "H191",
"H192", "H2", "H20", "H21", "H22", "H23", "H24", "H25", "H26",
"H27", "H28", "H29", "H3", "H30", "H31", "H32", "H33", "H34",
"H35", "H36", "H37", "H38", "H39", "H4", "H40", "H41", "H42",
"H43", "H44", "H45", "H46", "H47", "H48", "H49", "H5", "H50",
"H51", "H52", "H53", "H54", "H55", "H56", "H57", "H58", "H59",
"H6", "H60", "H61", "H62", "H63", "H64", "H65", "H66", "H67",
"H68", "H69", "H7", "H70", "H71", "H72", "H73", "H74", "H75",
"H76", "H77", "H78", "H79", "H8", "H80", "H81", "H82", "H83",
"H84", "H85", "H86", "H87", "H88", "H89", "H9", "H90", "H91",
"H92", "H93", "H94", "H95", "H96", "H97", "H98", "H99"), class = "factor"),
Hormone = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3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 11L, 15L, 15L, 11L, 11L, 9L, 15L, 9L, 9L,
11L, 11L, 14L, 1L, 5L, 4L, 4L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 15L, 15L, 14L, 13L, 15L, 15L, 11L, 9L, 9L,
11L, 9L, 11L, 1L, 20L, 1L, 20L, 20L, 20L, 20L, 1L, 1L, 4L,
20L, 20L, 20L, 15L, 15L, 14L, 15L, 1L, 15L, 15L, 20L, 11L,
11L, 11L, 11L, 15L, 10L, 10L, 16L, 10L, 12L, 10L, 17L, 8L,
16L, 12L, 8L, 4L, 4L, 8L, 20L, 10L, 1L, 20L, NA, 12L, 10L,
20L, 20L, 20L, 1L, 20L, 1L, 20L, 12L, 16L, 12L, 2L, 8L, 4L,
10L, 4L, 4L, 4L, 10L, 8L, 4L, 8L, 20L, 20L, 20L, NA, 20L,
1L, 20L, 1L, 8L, 20L, 1L, 1L, 7L, 17L, 19L, 19L, 12L, 10L,
12L, 19L, 10L, 10L, 10L, 17L), .Label = c("10-mei", "13-jun",
"14-apr", "14-mei", "17-mei", "18-jun", "21-jun", "21-mei",
"23-apr", "24-mei", "26-apr", "28-mei", "3-apr", "3-mei",
"30-apr", "31-mei", "4-jun", "5-jul", "7-jun", "7-mei"), class = "factor"),
FH = c(3.5, 6, 9, 16, 5.5, 12, 11.5, 4, 4.5, 6, 8, 5, 4.5,
3.5, 4, 5, 20, 42, 14, 40, 27, 42, 27, 26, 16, 18, 35, 17,
20, 28, 15, 20, 33, 32, 14.5, 14.5, 14.5, 35, 32, 12.5, 13.5,
12, 14.5, 12, 15, 14.5, 18, 18, 18.5, 35, 23, 25, 30, 37,
53, 27.5, 37, 25.5, 35, 47, 8.5, 20.5, 13, 14.5, 13.5, 18.5,
10.5, 10, 14.3, 18.5, 15.3, 11.7, 16, 15, 13.5, 26, 36, 30,
43, 23.5, 23.5, 31.5, 29, 30.5, 30, 29, 30, 24.5, 19, 23,
21.5, 26.5, 18.5, 20, 15, 12.3, 17, 12, 15, 13, 43614, 25,
27, 22.5, 35, 23.5, 30, 42, 42, 55, 32.5, 26, 26, 9.5, 4.5,
5.5, 5, 15.5, 10, 4.5, 8.5, 6, 5, 5.5, 5, 4.5, 30, 20, 16,
16, 20, 22, 30, 22, 25, 11, 13.5, 11, 11, 14, 6, NA, 5.5,
7, NA, 12, 14, 7, 9.5, 6.5, 9, 8.5, 12.5, 8, 27, 33, 35,
32, 17, 14, 22, 11, 17, 12, 25, 22, 15, 10, 5, 3, 4, NA,
5, 8, 4.5, 6, 7, 5, 5.5, 7, 42, 23, 23, 21, 14, 21, 17, 22,
19, 18, 17, 17), SRDT = structure(c(2L, 7L, 14L, NA, 7L,
8L, 7L, NA, NA, NA, 3L, NA, 18L, 15L, 17L, 17L, 18L, 18L,
NA, 18L, 15L, 17L, 15L, 20L, 2L, NA, 11L, 17L, 18L, 2L, 2L,
2L, 14L, 12L, 17L, 15L, 12L, 9L, 9L, 6L, 6L, 15L, 15L, 15L,
15L, NA, 17L, 15L, 10L, 11L, 11L, 10L, 11L, 17L, 5L, 21L,
6L, NA, 20L, 5L, 12L, 7L, NA, 17L, 17L, 15L, 15L, 10L, 10L,
6L, 10L, 10L, 21L, NA, 15L, 15L, 5L, 15L, 15L, 11L, 10L,
21L, 1L, 21L, 21L, 21L, 1L, 5L, 18L, 2L, 9L, 9L, NA, 12L,
10L, NA, 16L, 6L, 6L, 15L, 6L, 10L, 10L, 10L, 1L, 10L, 1L,
21L, 21L, 1L, 21L, 5L, 18L, 2L, 17L, 20L, 9L, 14L, 5L, 9L,
9L, 11L, NA, 18L, 10L, 18L, 20L, 4L, 9L, 7L, 2L, 2L, 7L,
5L, 17L, 17L, 11L, 10L, 12L, 2L, 14L, 19L, 19L, 19L, NA,
NA, 2L, 11L, 17L, 14L, 17L, 9L, 10L, 10L, 2L, 7L, 17L, 14L,
2L, 11L, 20L, 2L, 15L, 15L, 11L, 5L, NA, 10L, NA, 2L, 8L,
NA, NA, 14L, 5L, 15L, 15L, NA, 22L, NA, 9L, 9L, 19L, 9L,
9L, 22L, 20L, 13L, 7L, 20L, 15L, 20L), .Label = c("10-mei",
"11-jun", "13-jun", "13-mei", "14-mei", "17-mei", "18-jun",
"2-jul", "21-jun", "21-mei", "24-mei", "25-jun", "26-jun",
"28-jun", "28-mei", "3-mei", "31-mei", "4-jun", "5-jul",
"7-jun", "7-mei", "9-jul"), class = "factor"), MH = c(26,
50, 58, NA, 46, 58, 61, NA, NA, NA, 40, NA, 68, 48, 47, 42,
26, 50, NA, 48, 27, 42, 27, 48, 25, NA, 25, 17, 20, 18, 32,
19, 75, 75, 65, 70, 73, 73, 71, 65, 70, 60, 80, 70, 70, NA,
54, 45, 45, 45, 45, 40, 49, 53, 45, 27.5, 44, NA, NA, 47,
47, 62, NA, 75, 60, 75, 70, 65, 80, 67, 80, 75, 52, NA, 67,
68, 26, 55, 60, 60, 60, 31.5, 39, 30.5, 30, 29, 39, 39, 86,
74, 80, 76, NA, 69, 80, NA, 44, 70, 70, 65, 43, 60, 57, 57,
45, 60, 39, 35, 32.5, 27, 32.5, 43, 70, 75, 60, 66, 58, 48,
41, NA, 44, 42, NA, 44, 39, 40, 48, 53, 50, 50, 45, 45, 50,
13, 25, 11, 21, 20.5, 46, 44, 54, 25, 20, 25, NA, NA, 28,
33, 36, 40, 21, 36, 23.5, 21, 44, 60, 37, 37, 55, 24, 45,
45, 35, 30, 25, 12, 27, 10, NA, 53, 35, NA, NA, 43, 11, 13,
7, NA, 22, NA, 42, 46, NA, 41, 43, 40, 26, 45, 35, 29, 17,
22), SEEDT = structure(c(2L, 4L, 9L, NA, 4L, 5L, 4L, NA,
NA, NA, 4L, NA, 12L, 11L, 11L, 11L, 4L, 3L, NA, 4L, 15L,
4L, 8L, 5L, 7L, NA, 2L, 2L, 8L, 13L, 8L, NA, 13L, 8L, 15L,
15L, 8L, 7L, 7L, 10L, 10L, 11L, 6L, 10L, 10L, NA, 3L, 11L,
12L, 12L, 12L, 12L, 4L, 4L, 12L, 12L, 12L, NA, 9L, 12L, NA,
4L, NA, 2L, 15L, 2L, 15L, 14L, 10L, 12L, 12L, 11L, 11L, NA,
2L, 12L, 8L, 3L, 15L, 11L, 11L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 2L, 2L, 7L, 7L, NA, 8L, 10L, NA, 10L, 10L, 10L,
15L, 10L, 12L, 12L, 10L, 11L, 11L, 10L, 10L, 10L, 11L, 10L,
11L, 12L, 2L, 12L, 4L, 7L, 9L, 10L, 7L, 7L, 10L, NA, 12L,
10L, 15L, 2L, 4L, 8L, 8L, 4L, 4L, 13L, 12L, NA, NA, 4L, 7L,
NA, 7L, 13L, 13L, 13L, NA, NA, NA, 2L, 2L, NA, NA, NA, 8L,
NA, NA, 4L, 4L, 2L, NA, 4L, 2L, 7L, 7L, 7L, 2L, 2L, 15L,
1L, 15L, NA, 2L, 5L, NA, NA, 5L, 13L, NA, NA, NA, NA, NA,
16L, 16L, 13L, 16L, 7L, 1L, 7L, 16L, 7L, 7L, 7L, NA), .Label = c("11-jul",
"11-jun", "13-jun", "18-jun", "2-jul", "20-mei", "21-jun",
"25-jun", "28-jun", "28-mei", "31-mei", "4-jun", "5-jul",
"6-apr", "7-jun", "9-jul"), class = "factor"), FERMK = c(7L,
8L, 8L, 7L, 8L, 8L, 8L, 4L, NA, NA, 5L, 7L, 7L, 6L, 7L, 6L,
4L, 6L, NA, 4L, 3L, 4L, 4L, 4L, 2L, NA, 2L, 2L, 2L, 1L, 2L,
2L, 8L, 6L, 6L, 6L, 7L, 7L, 7L, 6L, 6L, 7L, 7L, 6L, 4L, 6L,
6L, 5L, 6L, 5L, 5L, 6L, 5L, 4L, 2L, 5L, NA, NA, 4L, 2L, 5L,
5L, NA, 7L, 7L, 8L, 6L, 6L, 7L, NA, 7L, 7L, 6L, 5L, 5L, 5L,
4L, 4L, 6L, 7L, 6L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 8L, 7L, 7L,
7L, 7L, 7L, 7L, NA, 7L, 7L, 7L, 7L,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L, 1L, NA, NA, 2L, 2L, 0L, 0L, NA, 1L, NA, 4L,
2L, 1L, 2L, 1L, 2L, 4L, 1L, 2L, 4L, 3L, NA), FF = c(39L,
43L, 50L, 60L, 43L, 20L, 46L, 39L, 29L, 32L, 43L, 32L, 29L,
29L, 29L, 32L, 64L, 64L, 85L, 64L, 64L, 67L, 64L, 64L, 71L,
71L, 64L, 67L, 71L, 102L, 64L, 85L, 43L, 43L, 36L, 36L, 36L,
43L, 43L, 32L, 32L, 32L, 29L, 29L, 29L, 29L, 43L, 43L, 43L,
50L, 46L, 50L, 50L, 50L, 57L, 43L, 50L, 43L, 64L, 50L, 39L,
39L, 32L, 32L, 36L, 36L, 32L, 32L, 29L, 36L, 29L, 29L, 32L,
32L, 39L, 46L, 53L, 50L, 50L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 36L, 36L, 39L, 9L, 36L, 36L, 32L, 29L, 29L,
32L, 29L, 32L, 46L, 43L, 46L, 43L, 43L, 43L, 43L, 46L, 46L,
50L, 43L, 43L, 43L, 36L, 36L, 39L, 36L, 46L, 36L, 36L, 43L,
32L, 32L, 32L, 32L, 36L, 60L, 60L, 67L, 60L, 64L, 60L, 71L,
57L, 67L, 64L, 57L, 50L, 50L, 57L, 43L, 60L, 46L, 43L, NA,
64L, 60L, 43L, 43L, 43L, 46L, 43L, 46L, 43L, 64L, 67L, 64L,
80L, 57L, 50L, 60L, 50L, 50L, 50L, 60L, 57L, 50L, 57L, 43L,
43L, 43L, NA, 43L, 46L, 43L, 46L, 57L, 43L, 46L, 46L, 88L,
71L, 74L, 74L, 64L, 60L, 64L, 74L, 60L, 60L, 60L, 71L), MF = c(78L,
85L, 95L, NA, 85L, 99L, 85L, NA, NA, NA, 80L, NA, 71L, 64L,
67L, 67L, 71L, 71L, NA, 71L, 64L, 67L, 64L, 74L, 78L, NA,
60L, 67L, 71L, 78L, 78L, 78L, 95L, 92L, 67L, 64L, 92L, 88L,
88L, 53L, 53L, 64L, 64L, 64L, 64L, NA, 67L, 64L, 57L, 60L,
60L, 57L, 60L, 67L, 50L, 43L, 53L, NA, 74L, 50L, 92L, 85L,
NA, 67L, 67L, 64L, 64L, 57L, 57L, 53L, 57L, 57L, 43L, NA,
64L, 64L, 50L, 64L, 64L, 60L, 57L, 43L, 46L, 43L, 43L, 43L,
46L, 50L, 71L, 78L, 88L, 88L, NA, 92L, 57L, NA, 39L, 53L,
53L, 64L, 53L, 57L, 57L, 57L, 46L, 57L, 46L, 43L, 43L, 46L,
43L, 50L, 71L, 78L, 67L, 74L, 88L, 95L, 50L, 88L, 88L, 60L,
NA, 71L, 57L, 71L, 74L, 49L, 88L, 85L, 78L, 78L, 85L, 50L,
67L, 67L, 60L, 57L, 92L, 78L, 95L, 102L, 102L, 102L, NA,
NA, 78L, 60L, 67L, 95L, 67L, 88L, 57L, 57L, 78L, 85L, 67L,
95L, 78L, 60L, 74L, 78L, 64L, 64L, 60L, 50L, NA, 57L, NA,
78L, 99L, NA, NA, 95L, 50L, 64L, 64L, NA, 106L, NA, 88L,
88L, 102L, 88L, 88L, 106L, 74L, 93L, 85L, 74L, 64L, 74L),
speed = c(0.08974359, 0.139534884, 0.18, 0.266666667, 0.127906977,
0.6, 0.25, 0.102564103, 0.155172414, 0.1875, 0.186046512,
0.15625, 0.155172414, 0.120689655, 0.137931034, 0.15625,
0.3125, 0.65625, 0.164705882, 0.625, 0.421875, 0.626865672,
0.421875, 0.40625, 0.225352113, 0.253521127, 0.546875, 0.253731343,
0.281690141, 0.274509804, 0.234375, 0.235294118, 0.76744186,
0.744186047, 0.402777778, 0.402777778, 0.402777778, 0.813953488,
0.744186047, 0.390625, 0.421875, 0.375, 0.5, 0.413793103,
0.517241379, 0.5, 0.418604651, 0.418604651, 0.430232558,
0.7, 0.5, 0.5, 0.6, 0.74, 0.929824561, 0.639534884, 0.74,
0.593023256, 0.546875, 0.94, 0.217948718, 0.525641026, 0.40625,
0.453125, 0.375, 0.513888889, 0.328125, 0.3125, 0.493103448,
0.513888889, 0.527586207, 0.403448276, 0.5, 0.46875, 0.346153846,
0.565217391, 0.679245283, 0.6, 0.86, 0.546511628, 0.546511628,
0.73255814, 0.674418605, 0.709302326, 0.697674419, 0.674418605,
0.697674419, 0.569767442, 0.527777778, 0.638888889, 0.551282051,
2.944444444, 0.513888889, 0.555555556, 0.46875, 0.424137931,
0.586206897, 0.375, 0.517241379, 0.40625, 948.1304348, 0.581395349,
0.586956522, 0.523255814, 0.813953488, 0.546511628, 0.697674419,
0.913043478, 0.913043478, 1.1, 0.755813953, 0.604651163,
0.604651163, 0.263888889, 0.125, 0.141025641, 0.138888889,
0.336956522, 0.277777778, 0.125, 0.197674419, 0.1875, 0.15625,
0.171875, 0.15625, 0.125, 0.5, 0.333333333, 0.23880597, 0.266666667,
0.3125, 0.366666667, 0.422535211, 0.385964912, 0.373134328,
0.171875, 0.236842105, 0.22, 0.22, 0.245614035, 0.139534884,
NA, 0.119565217, 0.162790698, NA, 0.1875, 0.233333333, 0.162790698,
0.220930233, 0.151162791, 0.195652174, 0.197674419, 0.27173913,
0.186046512, 0.421875, 0.492537313, 0.546875, 0.4, 0.298245614,
0.28, 0.366666667, 0.22, 0.34, 0.24, 0.416666667, 0.385964912,
0.3, 0.175438596, 0.11627907, 0.069767442, 0.093023256, NA,
0.11627907, 0.173913043, 0.104651163, 0.130434783, 0.122807018,
0.11627907, 0.119565217, 0.152173913, 0.477272727, 0.323943662,
0.310810811, 0.283783784, 0.21875, 0.35, 0.265625, 0.297297297,
0.316666667, 0.3, 0.283333333, 0.23943662), ratiofm = c(7,
4, 8, 7, 8, 8, 8, NA, NA, NA, 5, 3.5, NA, NA, NA, NA, 4,
6, NA, 4, 3, 2, 4, 4, 0.5, NA, 0.4, 0.4, 0.5, 0.2, 0.666666667,
0.5, 8, 6, 6, 6, 7, 7, 7, 3, 3, 3.5, 3.5, 6, 4, NA, 3, 2.5,
3, 5, 2.5, 3, 5, 4, 0.5, 1, NA, NA, 0.8, 0.333333333, 5,
5, NA, 7, 7, NA, 6, 6, 7, NA, 3.5, 7, 3, NA, 2.5, NA, 1,
1.333333333, 3, 3.5, 6, 1, 0.4, 0.4, 0.5, 0.4, 0.285714286,
0.333333333, 8, 7, 7, 7, NA, 7, 3.5, NA, 7, 7, 7, 7, 1.666666667,
1.666666667, 4, 1.25, 1.2, 2, 1.5, 0.285714286, 0.4, 0.25,
1, 2, NA, 6, 8, 7, 0.857142857, 6, NA, 7, 7, NA, NA, NA,
NA, NA, 3.5, 1.666666667, 5, 4, 2, 4, 2, 0.333333333, 0.333333333,
NA, 0.75, 0.5, NA, 1.5, 3, 5, 5, 6, NA, 6, 4, 2, 5, 5, 5,
5, NA, NA, 4, 4, 3, 2.5, 3, 2.5, 2.333333333, 3.5, 3.5, 0.6,
0.4, 0.75, 3, 1, NA, 2.5, 5, NA, NA, 2.5, 1.5, NA, NA, NA,
4, NA, 1.25, 2, 5, 2.5, 6, 2, 1, 3, 1.5, 1, 1.666666667,
NA)), class = "data.frame", row.names = c(NA, -192L))
It would be more clear with pictures of my graphs, but apparently I'm not allowed yet to include pictures in my posts, sorry
Thanks in advance for your help
you can try
library(tidyverse)
df %>%
as_tibble() %>%
ggplot(aes(x=fusion, y=FF)) +
geom_boxplot(aes(colour=fusion))+
ggsignif::geom_signif(comparisons = combn(levels(df$fusion), 2, simplify = F), step_increase = 0.3) +
ggpubr::stat_compare_means() +
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")

R, calculating last 3 average

I have the following data frame in R. It contains the statistics of each player in the Olympics basketball tournament
Sample Table
Each game is denoted by a number in the game column. I would like to create a new column with the average of the last 3 games. When following examples in similar posts, my biggest down fall is having games numbers instead of actual dates that seem to be required for other methods.
Any assistance would be greatly appreciated.
Thanks
EDIT:
To clarify a little more based on some of the solutions and suggestions. For each row I would like to have the new column show the Average minutes or points from the last 3 games. So far the suggestion make each row show the average of games 3, 4, & 5.
So for example.
Player A, game = 3
Avg Pts = mean(pts game1, pts game2, pts game3)
Player B, game = 4
Avg pts = mean(pts game2 ,pts game3, pts game4)
I hope that clears it up.
Thanks
Data:
I am very new at this. I hope this is the appropriate method for sharing data.
structure(list(Player = structure(c(1L, 2L, 6L, 8L, 17L, 21L,
23L, 24L, 24L, 24L, 24L, 25L, 26L, 15L, 20L, 20L, 12L, 15L, 11L,
5L, 15L, 16L, 14L, 9L, 20L, 11L, 18L, 4L, 12L, 9L, 4L, 9L, 20L,
12L, 5L, 13L, 22L, 7L, 11L, 20L, 4L, 5L, 10L, 11L, 14L, 19L,
3L, 7L, 14L, 5L), .Label = c("Adas Juskevicius", "Alex Abrines",
"Andrew Bogut", "Bojan Bogdanovic", "Boris Diaw", "Brock Motum",
"Dario Saric", "Dwight Lewis", "Facundo Campazzo", "Ike Diogu",
"Jianlian Yi", "Jonas Maciulis", "Kevin Durant", "Luis Scola",
"Mantas Kalnietis", "Matt Dellavedova", "Miguel Marriaga", "Milos Teodosic",
"Nikola Mirotic", "Pau Gasol", "Rafa Luz", "Ricky Rubio", "Roberto Acuna",
"Vaidas Kariniauskas", "Windi Graterol", "Zeljko Sakic"), class = "factor"),
Team = structure(c(8L, 6L, 2L, 12L, 12L, 3L, 1L, 8L, 8L,
8L, 8L, 12L, 5L, 8L, 6L, 6L, 8L, 8L, 4L, 7L, 8L, 2L, 1L,
1L, 6L, 4L, 10L, 5L, 8L, 1L, 5L, 1L, 6L, 8L, 7L, 11L, 6L,
5L, 4L, 6L, 5L, 7L, 9L, 4L, 1L, 6L, 2L, 5L, 1L, 7L), .Label = c("ARG",
"AUS", "BRZ", "CHN", "CRO", "ESP", "FRA", "LTU", "NGR", "SRB",
"USA", "VEN"), class = "factor"), Pos = structure(c(3L, 4L,
2L, 5L, 2L, 5L, 1L, 2L, 2L, 2L, 2L, 1L, 4L, 3L, 1L, 1L, 4L,
5L, 2L, 2L, 5L, 3L, 2L, 3L, 1L, 4L, 5L, 2L, 2L, 3L, 2L, 3L,
1L, 2L, 2L, 4L, 3L, 4L, 4L, 1L, 2L, 2L, 2L, 4L, 1L, 2L, 1L,
4L, 1L, 2L), .Label = c("C", "PF", "PG", "SF", "SG"), class = "factor"),
game = c(4L, 5L, 4L, 5L, 3L, 4L, 3L, 1L, 2L, 3L, 4L, 5L,
5L, 3L, 2L, 3L, 3L, 4L, 3L, 3L, 2L, 4L, 3L, 3L, 5L, 5L, 5L,
4L, 2L, 2L, 2L, 5L, 4L, 4L, 2L, 2L, 1L, 4L, 4L, 1L, 5L, 4L,
3L, 2L, 4L, 2L, 2L, 3L, 2L, 1L), Status = c(0L, 0L, 0L, 0L,
0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), Drafted = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85,
82, 80, 78, 77, 74, 68, 68, 68, 65, 64, 63, 62, 62, 61, 61,
60, 59, 59, 59, 58, 57, 57, 57, 56, 56, 56, 55, 55, 55, 55,
54, 54, 53, 53, 52, 51), Min = c(11.04, 1.44, 16.56, 2.88,
4.8, 1.92, 13.68, 3.84, 9.36, 2.64, 21.12, 17.04, 0.24, 36.48,
32.16, 23.28, 26.88, 17.28, 33.6, 28.56, 30.48, 19.92, 30.24,
25.92, 27.84, 34.8, 15.12, 36, 28.8, 29.04, 29.28, 21.36,
23.04, 18.72, 21.12, 25.2, 12.24, 27.12, 32.88, 31.92, 34.08,
18.24, 27.6, 32.64, 33.6, 32.88, 24.72, 34.8, 35.76, 31.44
), FIC = c(3.8, 1.5, 10.2, 1, 0, -1, 0.2, 0.5, -3.2, -1,
0.6, 4.5, -0.5, 15.6, 9.5, 11.1, 0.5, 7.8, 17, 16.8, 25.2,
10.5, 10, 6, 14.4, 6, 7.5, 15.5, 14.8, 6.2, 7.9, 3, 26.9,
0.8, 11.4, 16, -1, 4.9, 14.1, 18.5, 5.9, 6.5, 10, 10, 10,
8, 19, 9, 12.1, 7.5), FP = c(8, 4, 21.75, 2, 2.75, -0.5,
4.75, 1.5, 2.5, 1.25, 8.5, 13, 0, 35.25, 37, 32.25, 17, 18.5,
39.5, 34.25, 49, 19.25, 28.75, 20.25, 41.25, 27.5, 16.5,
39.25, 33.5, 29, 30.75, 13.25, 47.25, 9, 24.5, 28.5, 6.25,
19.5, 38.25, 40.25, 27.5, 17, 21.75, 37.5, 29, 21, 38.5,
30.75, 37.75, 25.75), FPM = c(0.72463768115942, 2.77777777777778,
1.31340579710145, 0.694444444444444, 0.572916666666667, -0.260416666666667,
0.347222222222222, 0.390625, 0.267094017094017, 0.473484848484848,
0.402462121212121, 0.762910798122066, 0, 0.966282894736842,
1.15049751243781, 1.38530927835052, 0.632440476190476, 1.07060185185185,
1.17559523809524, 1.19922969187675, 1.60761154855643, 0.96636546184739,
0.950727513227513, 0.78125, 1.48168103448276, 0.790229885057471,
1.09126984126984, 1.09027777777778, 1.16319444444444, 0.99862258953168,
1.05020491803279, 0.620318352059925, 2.05078125, 0.480769230769231,
1.16003787878788, 1.13095238095238, 0.51062091503268, 0.719026548672566,
1.16332116788321, 1.2609649122807, 0.806924882629108, 0.932017543859649,
0.78804347826087, 1.14889705882353, 0.863095238095238, 0.638686131386861,
1.55744336569579, 0.883620689655172, 1.05564876957494, 0.819020356234097
), PTS = c(5L, 2L, 15L, 0L, 0L, 0L, 2L, 0L, 0L, 0L, 6L, 9L,
0L, 17L, 13L, 16L, 10L, 16L, 18L, 11L, 21L, 6L, 12L, 10L,
19L, 20L, 7L, 28L, 21L, 10L, 18L, 10L, 23L, 4L, 7L, 16L,
0L, 7L, 20L, 26L, 22L, 10L, 7L, 19L, 14L, 6L, 9L, 15L, 23L,
9L), TPM = c(1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 0L, 2L, 0L, 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L,
6L, 3L, 0L, 3L, 2L, 0L, 1L, 0L, 3L, 4L, 1L, 2L, 2L, 5L, 3L,
0L, 0L, 0L, 3L, 1L, 1L, 3L, 2L, 0L, 5L, 0L, 1L, 1L, 3L, 0L,
2L, 6L, 4L, 2L)), .Names = c("Player", "Team", "Pos", "game",
"Status", "Drafted", "Min", "FIC", "FP", "FPM", "PTS", "TPM",
"Ast", "Reb", "BLK", "STL", "TO"), row.names = c(NA, 50L), class = "data.frame")
Using dplyr with mtcars example data:
library(dplyr)
mtcars %>%
group_by(cyl) %>%
mutate(last3mean = mean(tail(mpg, 3)))
In your case, instead of cyl and mpg, use Player and the column to aggregate.
Using data.table, (suggested by #akrun):
data.table as.data.table(mtcar‌​s)[, .(last3mean = mean(tail(mpg,3))), by = cyl]
You can use rollmeanr from the zoo package with dplyr. This has the feature that not only the last three games of a player is averaged, but the last three game moving average is computed for each player. The code is as follows:
library(dplyr)
library(zoo)
avg.last.3 <- function (x) if (length(x) < 3) rep(NA, length(x)) else rollmeanr(x, 3, fill = NA) ## 1.
res <- df %>% group_by(Player) %>% arrange(game) %>% ## 2.
mutate(Avg.Pts=avg.last.3(PTS)) %>% ## 3.
ungroup() %>% arrange(Player,game) ## 4.
Notes:
Define a function avg.last.3 that applies the function rollmeanr with window length of 3. rollmeanr specifies align="right" to average the last three games, and we pad any result that does not have three days to average by NA. Note that the if condition in this function is needed so that:
length of x is at least the window length for rollmeanr as required by rollmeanr
avg.last.3 returns a vector that is the same length as its input as required by mutate.
First group_by the Player. Since I noted that the game column is not necessarily sorted for each Player, we sort by game in ascending order.
Use mutate to create a new column Avg.Pts resulting from applying the avg.last.3 function on a column, for example PTS.
Finally, ungroup and present the result sorted by Player followed by game
Of course, you can get the average of any number of columns by:
mutate(Avg.Pts=avg.last.3(PTS), Avg.Min=avg.last.3(Min), Avg.Ast=avg.last.3(Ast), ...)
The results averaging only the PTS column is given by (printing only the first six columns plus PTS and Avg.Pts):
print(res[,c(colnames(res)[1:6],"PTS","Avg.Pts")],n=50)
### A tibble: 50 x 8
## Player Team Pos game Status Drafted PTS Avg.Pts
## <fctr> <fctr> <fctr> <int> <int> <dbl> <int> <dbl>
##1 Adas Juskevicius LTU PG 4 0 0 5 NA
##2 Alex Abrines ESP SF 5 0 0 2 NA
##3 Andrew Bogut AUS C 2 1 53 9 NA
##4 Bojan Bogdanovic CRO PF 2 1 59 18 NA
##5 Bojan Bogdanovic CRO PF 4 1 61 28 NA
##6 Bojan Bogdanovic CRO PF 5 1 55 22 22.666667
##7 Boris Diaw FRA PF 1 1 51 9 NA
##8 Boris Diaw FRA PF 2 1 57 7 NA
##9 Boris Diaw FRA PF 3 1 68 11 9.000000
##10 Boris Diaw FRA PF 4 1 55 10 9.333333
##11 Brock Motum AUS PF 4 0 0 15 NA
##12 Dario Saric CRO SF 3 1 53 15 NA
##13 Dario Saric CRO SF 4 1 56 7 NA
##14 Dwight Lewis VEN SG 5 0 0 0 NA
##15 Facundo Campazzo ARG PG 2 1 60 10 NA
##16 Facundo Campazzo ARG PG 3 1 64 10 NA
##17 Facundo Campazzo ARG PG 5 0 59 10 10.000000
##18 Ike Diogu NGR PF 3 1 55 7 NA
##19 Jianlian Yi CHN SF 2 1 55 19 NA
##20 Jianlian Yi CHN PF 3 1 74 18 NA
##21 Jianlian Yi CHN SF 4 1 56 20 19.000000
##22 Jianlian Yi CHN SF 5 1 62 20 19.333333
##23 Jonas Maciulis LTU PF 2 1 61 21 NA
##24 Jonas Maciulis LTU SF 3 1 78 10 NA
##25 Jonas Maciulis LTU PF 4 1 58 4 11.666667
##26 Kevin Durant USA SF 2 1 57 16 NA
##27 Luis Scola ARG C 2 1 52 23 NA
##28 Luis Scola ARG PF 3 1 65 12 NA
##29 Luis Scola ARG C 4 1 54 14 16.333333
##30 Mantas Kalnietis LTU SG 2 1 68 21 NA
##31 Mantas Kalnietis LTU PG 3 1 85 17 NA
##32 Mantas Kalnietis LTU SG 4 1 77 16 18.000000
##33 Matt Dellavedova AUS PG 4 1 68 6 NA
##34 Miguel Marriaga VEN PF 3 0 0 0 NA
##35 Milos Teodosic SRB SG 5 0 62 7 NA
##36 Nikola Mirotic ESP PF 2 1 54 6 NA
##37 Pau Gasol ESP C 1 1 56 26 NA
##38 Pau Gasol ESP C 2 1 82 13 NA
##39 Pau Gasol ESP C 3 1 80 16 18.333333
##40 Pau Gasol ESP C 4 1 59 23 17.333333
##41 Pau Gasol ESP C 5 1 63 19 19.333333
##42 Rafa Luz BRZ SG 4 0 0 0 NA
##43 Ricky Rubio ESP PG 1 1 57 0 NA
##44 Roberto Acuna ARG C 3 1 0 2 NA
##45 Vaidas Kariniauskas LTU PF 1 0 0 0 NA
##46 Vaidas Kariniauskas LTU PF 2 0 0 0 NA
##47 Vaidas Kariniauskas LTU PF 3 0 0 0 0.000000
##48 Vaidas Kariniauskas LTU PF 4 0 0 6 2.000000
##49 Windi Graterol VEN C 5 0 0 9 NA
##50 Zeljko Sakic CRO SF 5 0 0 0 NA
First split the data frame up by player
playerDFs <- split(origdata, origdata["Player"])
Then subset the last 3 games
playerLast3 <- lapply(playerDFs, function(x) x[tail(order(x[["game"]]),3), ])
Finally get your means
vapply(playerLast3, colMeans, numeric(ncol(origdata)))

Resources