vendredi 27 mai 2016

In R, search a dataframe for specific values, if found then select entire values and paste into new dataframe

In R, I am trying to search a column in a dataframe for a specific value. Once that value is found, I want to select the all of the data where that value exists, then copy and paste it into a new dataframe. I have a sample of the dataframe below. I am searching for a value "Storms" in the Storms column. If multiple "Storm" periods occur in a row, I want the program to select all of the data for that particular event and paste it into a new dataframe. The end goal is to get individual dataframes for each storm event. I am new in R so I don't have much to start with. I am planning on using the grep to search. Any help is appreciated.

DateTime    Rain (in)   Discharge (m^3/s)   TP (ug/s)   Storm
6/9/2014 0:00   0   0.105895833 9135.989427 No
6/9/2014 12:00  0   0.1055  9089.171776 No
6/10/2014 0:00  0   0.101979167 8726.453115 No
6/10/2014 12:00 0   0.095770833 8058.577397 No
6/11/2014 0:00  0   0.09625 8115.980183 Storm
6/11/2014 12:00 0   0.093625    7838.081703 No
6/12/2014 0:00  0   0.095   7989.704734 Storm
6/12/2014 12:00 0   0.093666667 7842.683567 No
6/13/2014 0:00  0   0.09375 7850.2027   Storm
6/13/2014 12:00 0   0.094125    7891.157636 Storm
6/14/2014 0:00  0   0.099458333 8456.241045 Storm
6/14/2014 12:00 0   0.101104167 8622.904117 Storm
6/15/2014 0:00  0   0.095229167 8007.199433 No
6/15/2014 12:00 0   0.091958333 7665.64586  No
6/16/2014 0:00  0   0.091979167 7665.606679 No
6/16/2014 12:00 0   0.088833333 7355.67491  No
6/17/2014 0:00  0   0.094333333 7918.867602 Storm
6/17/2014 12:00 0   0.120229167 10713.34331 Storm
6/18/2014 0:00  0   0.133854167 12259.29537 Storm
6/18/2014 12:00 0   0.1195625   10640.74235 No
6/19/2014 0:00  0   0.118395833 10504.82994 No
6/19/2014 12:00 0   0.116729167 10316.9778  No

File<-read.csv(file="C:\\R_Files\\P_Weather_12hr.csv",header=TRUE)
for (event in File){
  search<-ifelse(grep('Storm',File$Storm),select all of the data...
}

Aucun commentaire:

Enregistrer un commentaire