How to deal with " rank-deficient fit may be misleading" in R? - r

I'm trying to predict the values of test data set based on train data set, it is predicting the values (no errors) however the predictions deviate A LOT by the original values. Even predicting values around -356 although none of the original values exceeds 200 (and there are no negative values). The warning is bugging me as I think the values deviates a lot because of this warning.
Warning message:
In predict.lm(fit2, data_test) :
prediction from a rank-deficient fit may be misleading
any way I can get rid of this warning? the code is simple
fit2 <- lm(runs~., data=train_data)
prediction<-predict(fit2, data_test)
prediction
I searched a lot but tbh I couldn't understand much about this error.
str of test and train data set in case someone needs them
> str(train_data)
'data.frame': 36 obs. of 28 variables:
$ matchid : int 57 58 55 56 53 54 51 52 45 46 ...
$ TeamName : chr "South Africa" "West Indies" "South Africa" "West Indies" ...
$ Opp_TeamName : chr "West Indies" "South Africa" "West Indies" "South Africa" ...
$ TeamRank : int 4 3 4 3 4 3 10 7 5 1 ...
$ Opp_TeamRank : int 3 4 3 4 3 4 7 10 1 5 ...
$ Team_Top10RankingBatsman : int 0 1 0 1 0 1 0 0 2 2 ...
$ Team_Top50RankingBatsman : int 4 6 4 6 4 6 3 5 4 3 ...
$ Team_Top100RankingBatsman: int 6 8 6 8 6 8 7 7 7 6 ...
$ Opp_Top10RankingBatsman : int 1 0 1 0 1 0 0 0 2 2 ...
$ Opp_Top50RankingBatsman : int 6 4 6 4 6 4 5 3 3 4 ...
$ Opp_Top100RankingBatsman : int 8 6 8 6 8 6 7 7 6 7 ...
$ InningType : chr "1st innings" "2nd innings" "1st innings" "2nd innings" ...
$ Runs_OverAll : num 361 705 348 630 347 ...
$ AVG_Overall : num 27.2 20 23.3 19.1 24 ...
$ SR_Overall : num 128 121 120 118 118 ...
$ Runs_Last10Matches : num 118.5 71 102.1 71 78.6 ...
$ AVG_Last10Matches : num 23.7 20.4 20.9 20.4 23.2 ...
$ SR_Last10Matches : num 120 106 114 106 116 ...
$ Runs_BatingFirst : num 236 459 230 394 203 ...
$ AVG_BatingFirst : num 30.6 23.2 24 21.2 27.1 ...
$ SR_BatingFirst : num 127 136 123 125 118 ...
$ Runs_BatingSecond : num 124 262 119 232 144 ...
$ AVG_BatingSecond : num 25.5 18.3 22.8 17.8 22.8 ...
$ SR_BatingSecond : num 125 118 112 117 114 ...
$ Runs_AgainstTeam2 : num 88.3 118.3 76.3 103.9 49.3 ...
$ AVG_AgainstTeam2 : num 28.2 23 24.7 22.1 16.4 ...
$ SR_AgainstTeam2 : num 139 127 131 128 111 ...
$ runs : int 165 168 231 236 195 126 143 141 191 135 ...
> str(data_test)
'data.frame': 34 obs. of 28 variables:
$ matchid : int 59 60 61 62 63 64 65 66 69 70 ...
$ TeamName : chr "India" "West Indies" "England" "New Zealand" ...
$ Opp_TeamName : chr "West Indies" "India" "New Zealand" "England" ...
$ TeamRank : int 2 3 5 1 4 8 6 2 10 1 ...
$ Opp_TeamRank : int 3 2 1 5 8 4 2 6 1 10 ...
$ Team_Top10RankingBatsman : int 1 1 2 2 0 0 1 1 0 2 ...
$ Team_Top50RankingBatsman : int 5 6 4 3 4 2 5 5 3 3 ...
$ Team_Top100RankingBatsman: int 7 8 7 6 6 5 7 7 7 6 ...
$ Opp_Top10RankingBatsman : int 1 1 2 2 0 0 1 1 2 0 ...
$ Opp_Top50RankingBatsman : int 6 5 3 4 2 4 5 5 3 3 ...
$ Opp_Top100RankingBatsman : int 8 7 6 7 5 6 7 7 6 7 ...
$ InningType : chr "1st innings" "2nd innings" "2nd innings" "1st innings" ...
$ Runs_OverAll : num 582 618 470 602 509 ...
$ AVG_Overall : num 25 21.8 20.3 20.7 19.6 ...
$ SR_Overall : num 113 120 123 120 112 ...
$ Runs_Last10Matches : num 182 107 117 167 140 ...
$ AVG_Last10Matches : num 37.1 43.8 21 24.9 27.3 ...
$ SR_Last10Matches : num 111 153 122 141 120 ...
$ Runs_BatingFirst : num 319 314 271 345 294 ...
$ AVG_BatingFirst : num 23.6 17.8 20.6 20.3 19.5 ...
$ SR_BatingFirst : num 116.9 98.5 118 124.3 115.8 ...
$ Runs_BatingSecond : num 264 282 304 256 186 ...
$ AVG_BatingSecond : num 28 23.7 31.9 21.6 16.5 ...
$ SR_BatingSecond : num 96.5 133.9 129.4 112 99.5 ...
$ Runs_AgainstTeam2 : num 98.2 95.2 106.9 75.4 88.5 ...
$ AVG_AgainstTeam2 : num 45.3 42.7 38.1 17.7 27.1 ...
$ SR_AgainstTeam2 : num 125 138 152 110 122 ...
$ runs : int 192 196 159 153 122 120 160 161 70 145 ...
In simple word, how can I get rid of this warning so that it doesn't effect my predictions?
(Intercept) matchid TeamNameBangladesh
1699.98232628 -0.06793787 59.29445330
TeamNameEngland TeamNameIndia TeamNameNew Zealand
347.33030177 -499.40074338 -179.19192936
TeamNamePakistan TeamNameSouth Africa TeamNameSri Lanka
-272.71610614 -3.54867488 -45.27920191
TeamNameWest Indies Opp_TeamNameBangladesh Opp_TeamNameEngland
-345.54349798 135.05901017 108.04227770
Opp_TeamNameIndia Opp_TeamNameNew Zealand Opp_TeamNamePakistan
-162.24418387 -60.55364436 -114.74599364
Opp_TeamNameSouth Africa Opp_TeamNameSri Lanka Opp_TeamNameWest Indies
196.90856999 150.70170068 -6.88997714
TeamRank Opp_TeamRank Team_Top10RankingBatsman
NA NA NA
Team_Top50RankingBatsman Team_Top100RankingBatsman Opp_Top10RankingBatsman
NA NA NA
Opp_Top50RankingBatsman Opp_Top100RankingBatsman InningType2nd innings
NA NA 24.24029455
Runs_OverAll AVG_Overall SR_Overall
-0.59935875 20.12721378 -13.60151334
Runs_Last10Matches AVG_Last10Matches SR_Last10Matches
-1.92526750 9.24182916 1.23914363
Runs_BatingFirst AVG_BatingFirst SR_BatingFirst
1.41001672 -9.88582744 -6.69780509
Runs_BatingSecond AVG_BatingSecond SR_BatingSecond
-0.90038727 -7.11580086 3.20915976
Runs_AgainstTeam2 AVG_AgainstTeam2 SR_AgainstTeam2
3.35936312 -5.90267210 2.36899131

You can have a look at this detailed discussion :
predict.lm() in a loop. warning: prediction from a rank-deficient fit may be misleading
In general, multi-collinearity can lead to a rank deficient matrix in logistic regression.
You can try applying PCA to tackle the multi-collinearity issue and then apply logistic regression afterwards.

Related

Isolate Data Frame from Data Frame for Multiple Time Series Plot

I want to extract temperature (temp_c) at specific pressure level (press_hpa). As I am filtering my data (dat) using dplyr, I'm creating another data frame which contains the same columns numbers (15) and different length of observation. There were so many solution to plot multiple time series from column but I cant match the solution.. How to plot a multiple time series showing temperature at different level(x = date, y = temp_c, legend = Press_1000, Press_925, Press_850, Press_700)? Kindly help.. Thank you..
library(ggplot2),
library(dplyr)
library(reshape2)
setwd("C:/Users/Hp/Documents/yr/climatology/")
dat <- read.csv("soundingWMKD.csv", head = TRUE, stringsAsFactors = F)
str(dat)
'data.frame': 6583 obs. of 15 variables:
$ X : int 1 2 3 4 5 6 7 8 9 10 ...
$ pres_hpa : num 1006 1000 993 981 1005 ...
$ hght_m : int 16 70 132 238 16 62 141 213 302 329 ...
$ temp_c : num 24 23.6 23.2 24.6 24.2 24.2 24 23.8 23.3 23.2 ...
$ dwpt_c : num 23.4 22.4 21.5 21.6 23.6 23.1 22.9 22.7 22 21.8 ...
$ relh_pct : int 96 93 90 83 96 94 94 94 92 92 ...
$ mixr_g_kg: num 18.4 17.4 16.6 16.9 18.6 ...
$ drct_deg : int 0 0 NA NA 190 210 212 213 215 215 ...
$ sknt_knot: int 0 0 NA NA 1 3 6 8 11 11 ...
$ thta_k : num 297 297 297 299 297 ...
$ thte_k : num 350 347 345 349 351 ...
$ thtv_k : num 300 300 300 302 300 ...
$ date : chr "2017-11-02" "2017-11-02" "2017-11-02" "2017-11-02" ...
$ from_hr : int 0 0 0 0 0 0 0 0 0 0 ...
$ to_hr : int 0 0 0 0 0 0 0 0 0 0 ...
Press_1000 <- filter(dat,dat$pres_hpa == 1000)
Press_925 <- filter(dat,dat$pres_hpa == 925)
Press_850 <- filter(dat,dat$pres_hpa == 850)
Press_700 <- filter(dat,dat$pres_hpa == 700)
date <- as.Date(dat$date, "%m-%d-%y")
str(Press_1000)
'data.frame': 80 obs. of 15 variables:
$ X : int 2 6 90 179 267 357 444 531 585 675 ...
$ pres_hpa : num 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ...
$ hght_m : int 70 62 63 63 62 73 84 71 74 78 ...
$ temp_c : num 23.6 24.2 24.4 24.2 25.4 24 23.8 24 23.8 24 ...
$ dwpt_c : num 22.4 23.1 23.2 22.3 23.9 23.1 23.4 23 23 23.1 ...
$ relh_pct : int 93 94 93 89 91 95 98 94 95 95 ...
$ mixr_g_kg: num 17.4 18.2 18.3 17.3 19.1 ...
$ drct_deg : int 0 210 240 210 210 340 205 290 315 0 ...
$ sknt_knot: int 0 3 2 3 3 2 4 1 1 0 ...
$ thta_k : num 297 297 298 297 299 ...
$ thte_k : num 347 350 351 348 354 ...
$ thtv_k : num 300 301 301 300 302 ...
$ date : chr "2017-11-02" "2017-11-03" "2017-11-04" "2017-11-05" ...
$ from_hr : int 0 0 0 0 0 0 0 0 0 0 ...
$ to_hr : int 0 0 0 0 0 0 0 0 0 0 ...
str(Press_925)
'data.frame': 79 obs. of 15 variables:
$ X : int 13 96 187 272 365 450 537 593 681 769 ...
$ pres_hpa : num 925 925 925 925 925 925 925 925 925 925 ...
$ hght_m : int 745 747 746 748 757 764 757 758 763 781 ...
$ temp_c : num 21.8 22 22.4 23.2 22.2 20.6 22.4 22 22.4 22.2 ...
$ ... 'truncated'
all_series = rbind(date,Press_1000,Press_925,Press_850,Press_700)
meltdf <- melt(all_series,id.vars ="date")
ggplot(meltdf,aes(x=date,y=value,colour=variable,group=variable)) +
geom_line()
There are two ways of approaching this. What you go for may depend on the bedrock question (which we don't know).
1) For each data.frame, you have all the necessary columns and you can plot each source (data.frame) using e.g.
ggplot()... +
geom_line(data = Press_1000, aes(...)) +
geom_line(data = Press_925, aes(...)) ...
Note that you will have to specify color for each source and having a legend with that is PITA.
2) Combine all data.frames into one big object and create an additional column indicating the origin of the data (from which data.frame the observation is from). This would be your mapping variable (e.g. color, fill, group)in your current aes call. Instant legend.

Trying to draw a SPC Chart in R

I am trying to create a control chart using the code below but I am getting the error below. The data has the first Column as date then 12 other columns with different variables of data.
library("qcc")
attach(data)
Data_Frame_Data <- as.data.frame.matrix(data)
q <- qcc(Cancer_Activity
, type="xbar"
, nsigmas=3)
Error in sd.xbar(c(1396310400, 1398902400, 1401580800, 1404172800,
1406851200, : group sizes must be larger than one
This is the output when I run str(data)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 48 obs. of 13 variables:
$ Date : POSIXct, format: "2014-04-01" "2014-05-01" "2014-06-01" "2014-07-01" ...
$ CW_Activity : num 37 29.5 34 46 39.5 41.5 42 40 46 39.5 ...
$ CW_Breach : num 3.5 6 8.5 10 5.5 8 4.5 3 3.5 4 ...
$ ICHT_Activity: num 73.5 89 60 83.5 85 88.5 65.5 80 75.5 74 ...
$ ICHT_Breach : num 8 11.5 11.5 12 11 15 9.5 14 8.5 16.5 ...
$ LNWH_Activity: num 67 76.5 56 79.5 67 83 77.5 67 66 60.5 ...
$ LNWH_Breach : num 10 12.5 13 14 10.5 16 16.5 12 5 13.5 ...
$ THH_Activity : num 30 26 24.5 36 31 25 33 21.5 42 25.5 ...
$ THH_Breach : num 2 3 2 1 5 1.5 3.5 0.5 3.5 3 ...
$ RBH_Activity : num 2.5 5 6.5 7 6.5 7.5 3.5 9 8 6.5 ...
$ RBH_Breach : num 0.5 1 2 2 4 4 1 2 2.5 2 ...
$ NWL_Activity : num 210 226 181 252 229 ...
$ NWL_Breach : num 24 34 37 39 36 44.5 35 31.5 23 39 ...

Error in evalSummaryFunction Caret R

I have this data set
'data.frame': 212300 obs. of 19 variables:
$ FL_DATE_MDD_MMDD : int 101 101 101 101 101 101 101 101 101 101 ...
$ FL_DATE : int 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 ...
$ UNIQUE_CARRIER : Factor w/ 13 levels "9E","AA","AS",..: 11 10 2 5 8 9 11 10 10 10 ...
$ DEST : Factor w/ 150 levels "ABE","ABQ","ALB",..: 111 70 82 8 8 31 110 44 53 80 ...
$ DEST_CITY_NAME : Factor w/ 148 levels "Akron, OH","Albany, NY",..: 107 61 96 9 9 29 106 36 97 78 ...
$ ROUNDED_TIME : int 451 451 551 551 551 551 551 551 551 551 ...
$ CRS_DEP_TIME : int 500 520 600 600 600 600 600 600 602 607 ...
$ DEP_DEL15 : Factor w/ 2 levels "No","Yes": 1 2 1 1 1 1 1 2 1 1 ...
$ CRS_ARR_TIME : int 746 813 905 903 855 815 901 744 901 841 ...
$ Conditions : Factor w/ 28 levels "Blowing Snow",..: 2 2 2 2 2 2 2 2 2 2 ...
$ Dew.PointC : num -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 ...
$ Events : Factor w/ 10 levels "","Fog","Fog-Rain",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Humidity : int 68 68 71 71 71 71 71 71 71 71 ...
$ Sea.Level.PressurehPa: num 1021 1021 1022 1022 1022 ...
$ TemperatureC : num -9.4 -9.4 -10 -10 -10 -10 -10 -10 -10 -10 ...
$ VisibilityKm : num 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 ...
$ Wind.Direction : Factor w/ 18 levels "Calm","East",..: 9 9 7 7 7 7 7 7 7 7 ...
$ WindDirDegrees : int 320 320 330 330 330 330 330 330 330 330 ...
$ Wind.SpeedKm.h : num 20.4 20.4 13 13 13 13 13 13 13 13 ...
- attr(*, "na.action")=Class 'omit' Named int [1:22539] 3 32 45 87 94 325 472 548 949 1333 ...
.. ..- attr(*, "names")= chr [1:22539] "3" "32" "45" "87" ...
and when I execute the following in Caret
plsFit3x10cv <-train(DEP_DEL15~., data=training3, method="pls",trControl=ctrl,metric="ROC",preProc=c("center","scale"))
I get the error:
Error in evalSummaryFunction(y, wts = weights, ctrl = trControl, lev = classLevels, :
train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl()
The answer to your question is in the error message. It says train()'s use of ROC codes requires class probabilities. See the classProbs option of trainControl(). So, you need to use classProbs = TRUE in trainControl(), and of course, set summaryFunction = twoClassSummary (if you have not already done so).
ctrl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
summaryFunction = twoClassSummary)
plsFit3x10cv <-train(DEP_DEL15~.,
data=training3,
method="pls",
preProc=c("center","scale"),
metric="ROC",
trControl=ctrl)

Caret error: "all the Accuracy metric values are missing"

I'm getting the following error and I don't know what may have gone wrong.
I'm using R Studio with the 3.1.3 version of R for Windows 8.1 and using the Caret package for datamining.
I have the following training data:
str(training)
'data.frame': 212300 obs. of 21 variables:
$ FL_DATE_MDD_MMDD : int 101 101 101 101 101 101 101 101 101 101 ...
$ FL_DATE : int 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 1012013 ...
$ UNIQUE_CARRIER : Factor w/ 13 levels "9E","AA","AS",..: 11 10 2 5 8 9 11 10 10 10 ...
$ DEST : Factor w/ 150 levels "ABE","ABQ","ALB",..: 111 70 82 8 8 31 110 44 53 80 ...
$ DEST_CITY_NAME : Factor w/ 148 levels "Akron, OH","Albany, NY",..: 107 61 96 9 9 29 106 36 97 78 ...
$ ROUNDED_TIME : int 451 451 551 551 551 551 551 551 551 551 ...
$ CRS_DEP_TIME : int 500 520 600 600 600 600 600 600 602 607 ...
$ DEP_DEL15 : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 2 1 1 ...
$ CRS_ARR_TIME : int 746 813 905 903 855 815 901 744 901 841 ...
$ Conditions : Factor w/ 28 levels "Blowing Snow",..: 2 2 2 2 2 2 2 2 2 2 ...
$ Dew.PointC : num -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 -14.4 ...
$ Events : Factor w/ 10 levels "","Fog","Fog-Rain",..: 1 1 1 1 1 1 1 1 1 1 ...
$ Gust.SpeedKm.h : num NA NA NA NA NA NA NA NA NA NA ...
$ Humidity : int 68 68 71 71 71 71 71 71 71 71 ...
$ Precipitationmm : num NA NA NA NA NA NA NA NA NA NA ...
$ Sea.Level.PressurehPa: num 1021 1021 1022 1022 1022 ...
$ TemperatureC : num -9.4 -9.4 -10 -10 -10 -10 -10 -10 -10 -10 ...
$ VisibilityKm : num 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 16.1 ...
$ Wind.Direction : Factor w/ 18 levels "Calm","East",..: 9 9 7 7 7 7 7 7 7 7 ...
$ WindDirDegrees : int 320 320 330 330 330 330 330 330 330 330 ...
$ Wind.SpeedKm.h : num 20.4 20.4 13 13 13 13 13 13 13 13 ...
- attr(*, "na.action")=Class 'omit' Named int [1:22539] 3 32 45 87 94 325 472 548 949 1333 ...
.. ..- attr(*, "names")= chr [1:22539] "3" "32" "45" "87" ...
and when I execute the following command:
ldaModel <- train(DEP_DEL15~.,data=training,method="lda",preProc=c("center","scale"),na.remove=TRUE)
I get:
Something is wrong; all the Accuracy metric values are missing:
Accuracy Kappa
Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA
Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA
NA's :1 NA's :1
Error in train.default(x, y, weights = w, ...) : Stopping
It is probably due to having about outcome factor with levels "0" and "1".
There is a specific warning issued when this happens: At least one of the class levels are not valid R variables names; This may cause errors if class probabilities are generated because the variables names will be converted to: X0, X1"
It seems that people uniformly ignore warnings so I'm going to make this throw an error in the next version.
If the variables Gust.SpeedKm.h and Precipitationmm contain only NA's try omitting those variables from your data before running the model. If they contain partial NA's and you think they could have predictive value as features then use imputation. Follow this documentation for pre-processing in caret, including imputation.

Split and unsplit a dataframe in four parts

I'd like to split a dataframe in 4 equals parts, because I'd like to use the 4 cores of my computer.
I did this :
df2 <- split(df, 1:4)
unsplit(df2, f=1:4)
and that
df2 <- split(df, 1:4)
unsplit(df2, f=c('1','2','3','4')
But the unsplit function did not work, I have these warnings messages
1: In split.default(seq_along(x), f, drop = drop, ...) :
data length is not a multiple of split variable
...
Do you have an idea of the reason ?
How many rows in df? You will get that warning if the number of rows in your table is not divisible by 4. I think you are using the split factor f incorrectly, unless what you want to do is put each subsequent row into a different split data.frame.
If you really want to split your data into 4 dataframes. one row after the other then make your splitting factor the same size as the number of rows in your dataframe using rep_len like this:
## Split like this:
split(df , f = rep_len(1:4, nrow(df) ) )
## Unsplit like this:
unsplit( split(df , f = rep_len(1:4, nrow(df) ) ) , f = rep_len(1:4,nrow(df) ) )
Hopefully this example illustrates why the error occurs and how to avoid it (i.e. use a proper splitting factor!).
## Want to split our data.frame into two halves, but rows not divisible by 2
df <- data.frame( x = runif(5) )
df
## Splitting still works but...
## We get a warning because the split factor 'f' was not recycled as a multiple of it's length
split( df , f = 1:2 )
#$`1`
# x
#1 0.6970968
#3 0.5614762
#5 0.5910995
#$`2`
# x
#2 0.6206521
#4 0.1798006
Warning message:
In split.default(x = seq_len(nrow(x)), f = f, drop = drop, ...) :
data length is not a multiple of split variable
## Instead let's use the same split levels (1:2)...
## but make it equal to the length of the rows in the table:
splt <- rep_len( 1:2 , nrow(df) )
splt
#[1] 1 2 1 2 1
## Split works, and f is not recycled because there are
## the same number of values in 'f' as rows in the table
split( df , f = splt )
#$`1`
# x
#1 0.6970968
#3 0.5614762
#5 0.5910995
#$`2`
# x
#2 0.6206521
#4 0.1798006
## And unsplitting then works as expected and reconstructs our original data.frame
unsplit( split( df , f = splt ) , f = splt )
# x
#1 0.6970968
#2 0.6206521
#3 0.5614762
#4 0.1798006
#5 0.5910995
In the R language 'split' example . . .
aq <- airquality
g <- aq$Month
l <- split(aq,g)
After the 'scale' function is executed
l <- lapply(l, transform, Ozone = scale(Ozone))
I am guessing that at one time in R history
the function 'scale' did not add extra attributes
to the column it is modifying.
..$ Ozone : num ...
.. ..- attr(*, "scaled:center")= num 29.4
.. ..- attr(*, "scaled:scale")= num 18.2
As seen in here . . .
> str(l)
List of 5
$ 5:'data.frame': 31 obs. of 6 variables:
..$ Ozone : num [1:31, 1] 0.782 0.557 -0.523 -0.253 NA ...
.. ..- attr(*, "scaled:center")= num 23.6
.. ..- attr(*, "scaled:scale")= num 22.2
..$ Solar.R: int [1:31] 190 118 149 313 NA NA 299 99 19 194 ...
..$ Wind : num [1:31] 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
..$ Temp : int [1:31] 67 72 74 62 56 66 65 59 61 69 ...
..$ Month : int [1:31] 5 5 5 5 5 5 5 5 5 5 ...
..$ Day : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
$ 6:'data.frame': 30 obs. of 6 variables:
..$ Ozone : num [1:30, 1] NA NA NA NA NA ...
.. ..- attr(*, "scaled:center")= num 29.4
.. ..- attr(*, "scaled:scale")= num 18.2
..$ Solar.R: int [1:30] 286 287 242 186 220 264 127 273 291 323 ...
..$ Wind : num [1:30] 8.6 9.7 16.1 9.2 8.6 14.3 9.7 6.9 13.8 11.5 ...
..$ Temp : int [1:30] 78 74 67 84 85 79 82 87 90 87 ...
..$ Month : int [1:30] 6 6 6 6 6 6 6 6 6 6 ...
..$ Day : int [1:30] 1 2 3 4 5 6 7 8 9 10 ...
$ 7:'data.frame': 31 obs. of 6 variables:
..$ Ozone : num [1:31, 1] 2.399 -0.32 -0.857 NA 0.154 ...
.. ..- attr(*, "scaled:center")= num 59.1
.. ..- attr(*, "scaled:scale")= num 31.6
..$ Solar.R: int [1:31] 269 248 236 101 175 314 276 267 272 175 ...
..$ Wind : num [1:31] 4.1 9.2 9.2 10.9 4.6 10.9 5.1 6.3 5.7 7.4 ...
..$ Temp : int [1:31] 84 85 81 84 83 83 88 92 92 89 ...
..$ Month : int [1:31] 7 7 7 7 7 7 7 7 7 7 ...
..$ Day : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
$ 8:'data.frame': 31 obs. of 6 variables:
..$ Ozone : num [1:31, 1] -0.528 -1.284 -1.108 0.455 -0.629 ...
.. ..- attr(*, "scaled:center")= num 60
.. ..- attr(*, "scaled:scale")= num 39.7
..$ Solar.R: int [1:31] 83 24 77 NA NA NA 255 229 207 222 ...
..$ Wind : num [1:31] 6.9 13.8 7.4 6.9 7.4 4.6 4 10.3 8 8.6 ...
..$ Temp : int [1:31] 81 81 82 86 85 87 89 90 90 92 ...
..$ Month : int [1:31] 8 8 8 8 8 8 8 8 8 8 ...
..$ Day : int [1:31] 1 2 3 4 5 6 7 8 9 10 ...
$ 9:'data.frame': 30 obs. of 6 variables:
..$ Ozone : num [1:30, 1] 2.674 1.928 1.721 2.467 0.644 ...
.. ..- attr(*, "scaled:center")= num 31.4
.. ..- attr(*, "scaled:scale")= num 24.1
..$ Solar.R: int [1:30] 167 197 183 189 95 92 252 220 230 259 ...
..$ Wind : num [1:30] 6.9 5.1 2.8 4.6 7.4 15.5 10.9 10.3 10.9 9.7 ...
..$ Temp : int [1:30] 91 92 93 93 87 84 80 78 75 73 ...
..$ Month : int [1:30] 9 9 9 9 9 9 9 9 9 9 ...
..$ Day : int [1:30] 1 2 3 4 5 6 7 8 9 10 ...
But now it does add those attributes
..$ Ozone : num ...
.. ..- attr(*, "scaled:center")= num 29.4
.. ..- attr(*, "scaled:scale")= num 18.2
and the very simple 'unsplit' function is not programmed to handle those attributes.
> unsplit(l,g)
Error in xj[i, , drop = FALSE] : (subscript) logical subscript too long
The (direct and simple) solution is to get rid of those attributes.
attributes(l[[1]]$Ozone) <- NULL
attributes(l[[2]]$Ozone) <- NULL
attributes(l[[3]]$Ozone) <- NULL
attributes(l[[4]]$Ozone) <- NULL
attributes(l[[5]]$Ozone) <- NULL
Then try to unsplit again.
str( unsplit(l,g) )
> str( unsplit(l,g) )
'data.frame': 153 obs. of 6 variables:
$ Ozone : num 0.782 0.557 -0.523 -0.253 NA ...
$ Solar.R: int 190 118 149 313 NA NA 299 99 19 194 ...
$ Wind : num 7.4 8 12.6 11.5 14.3 14.9 8.6 13.8 20.1 8.6 ...
$ Temp : int 67 72 74 62 56 66 65 59 61 69 ...
$ Month : int 5 5 5 5 5 5 5 5 5 5 ...
$ Day : int 1 2 3 4 5 6 7 8 9 10 ...
So, now it works.
Andre Mikulec

Resources