[R] Subset()
Jim Lemon
drjimlemon at gmail.com
Sun Jan 22 05:18:40 CET 2017
Hi Elise,
One of the quirks of POSIXt time values is that they are lists. This
should give you the plot:
plot(Soil_Temp~as.numeric(DateTime),eldf,xaxt="n",xlab="DateTime")
and this the x axis:
axis.POSIXct(1,eldf$DateTime)
If you want a different format for the date values on the axis, look
at the "format" argument.
Jim
On Sun, Jan 22, 2017 at 2:32 PM, Elise LIKILIKI
<elise.likiliki at gmail.com> wrote:
> Hi Jim,
>
> I'm really sorry to bother you, but finally I have another problem, then
> when I try to make a plot
>>plot(Soil_Temp_Avg~DateTime,eldf2)
>
> I have an error message saying :
> Error in (function (formula, data = NULL, subset = NULL, na.action =
> na.fail, : invalid type (list) for variable 'DateTime'
>
>
> 2017-01-22 3:42 GMT+01:00 Elise LIKILIKI <elise.likiliki at gmail.com>:
>>
>> Hi Jim,
>>
>> Thank you so much, it works with your method !! I'm going to be able to
>> process my data, thanks again !
>>
>> Regards,
>>
>> Elise
>>
>> 2017-01-21 23:32 GMT+01:00 Jim Lemon <drjimlemon at gmail.com>:
>>>
>>> Hi Elise,
>>> If I create a CSV file like your example and read it into a data frame:
>>>
>>> eldf<-read.csv("el.csv")
>>>
>>> Then convert the first field to POSIXt dates:
>>>
>>> eldf$DateTime<-strptime(eldf$DateTime,"%Y-%m-%d %H:%M:%S")
>>> class(eldf$DateTime)
>>> [1] "POSIXlt" "POSIXt"
>>>
>>> I can subset the file like this:
>>>
>>> time_after<-strptime("2017-01-09 18:00:00","%Y-%m-%d %H:%M:%S")
>>> > time_after
>>> [1] "2017-01-09 18:00:00 AEDT"
>>> > eldf[eldf$DateTime >= time_after,]
>>> DateTime RECORD PTemp PPFD_Avg Air_Temp_Avg RH_avg Soil_Temp
>>> 7 2017-01-09 18:00:00 6 21.26 -48.83 -38.49 -0.415
>>> 79
>>> 8 2017-01-09 18:15:00 7 21.21 -52.23 -39.00 -0.642
>>> 79
>>> 9 2017-01-09 18:30:00 8 21.12 -54.68 -39.41 -0.805
>>> 79
>>> 10 2017-01-09 18:45:00 9 21.04 -56.44 .39.74 -0.939
>>> 79
>>> 11 2017-01-09 19:00:00 10 20.99 -57.71 -40.01 -1.046
>>> 79
>>> 12 2017-01-09 19:15:00 11 20.91 -58.66 -40.25 -1.137
>>> 79
>>> 13 2017-01-09 19:30:00 12 21.83 -59.39 -40.46 -1.208
>>> 79
>>>
>>> Perhaps this will do what you want.
>>>
>>> No need to apologize for your English, I could not make myself
>>> understood in French.
>>>
>>> Jim
>>>
>>> On Sun, Jan 22, 2017 at 4:15 AM, Elise LIKILIKI
>>> <elise.likiliki at gmail.com> wrote:
>>> > Hi Jim,
>>> >
>>> > Yes exactly it returns "POSIXct" "POSIXt"
>>> > Find attached a screenshot showing my data in "data" object.
>>> > I don't need the data before 2017-01-10 11:00:00 nor columns : Records
>>> > and
>>> > Ptemp.
>>> > I've tried with subset() and with [ ] but I still have some rows
>>> > containing
>>> > data before 2017-01-10 11:00:00.
>>> >
>>> > I'm french so I am really sorry about my english
>>> >
>>> > 2017-01-21 11:41 GMT+01:00 Jim Lemon <drjimlemon at gmail.com>:
>>> >>
>>> >> Hi Elise,.
>>> >> I would ask:
>>> >>
>>> >> class(data$DateTime)
>>> >>
>>> >> and see if it returns:
>>> >>
>>> >> "POSIXct" "POSIXt"
>>> >>
>>> >> Jim
>>> >>
>>> >>
>>> >> On Sat, Jan 21, 2017 at 3:02 AM, Elise LIKILIKI
>>> >> <elise.likiliki at gmail.com> wrote:
>>> >> > Hello,
>>> >> >
>>> >> > I have a dataset containing Date Time, Air Temperature, PPFD, Sol
>>> >> > Temperature...
>>> >> > The first data are false so I would like to extract the other ones.
>>> >> > I've tried :
>>> >> >>data1<-subset(data,DateTime>=as.POSIXct("2017-01-10
>>> >> > 11:00:00",format="%Y-%m-%d
>>> >> >
>>> >> >
>>> >> > %H:%M:%S"),select=c(DateTime,PPFD_Avg,Air_Temp_Avg,RH_Avg,Soil_Temp_Avg))
>>> >> > But I still have 4 rows with data from 2017-01-10 10:00:00 to
>>> >> > 2017-01-10
>>> >> > 10:45:00 and I don't understand why.
>>> >> >
>>> >> > Does anyone could help me please.
>>> >> >
>>> >> > Thanks,
>>> >> >
>>> >> > Elise LIKILIKI
>>> >> >
>>> >> > [[alternative HTML version deleted]]
>>> >> >
>>> >> > ______________________________________________
>>> >> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> >> > https://stat.ethz.ch/mailman/listinfo/r-help
>>> >> > PLEASE do read the posting guide
>>> >> > http://www.R-project.org/posting-guide.html
>>> >> > and provide commented, minimal, self-contained, reproducible code.
>>> >
>>> >
>>
>>
>
More information about the R-help
mailing list