Identifying column type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Identifying column type

Steven Yen
I have data of mixed types in a data frame - date and numeric, as shown
in summary below. How do I identify the column(s) that is/are not
numeric, in this case, the first. All I want is to identify the
column(s) and so that I can remove it/them from the data frame Thanks.

> summary(mydata)

Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2
1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median
:2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01
06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd
Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max.
:2825.8


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying column type

Jeff Newmiller
Does

sapply( mydata, inherits, what = "POSIXt" )

give you any ideas?

On April 9, 2021 8:25:36 PM PDT, Steven Yen <[hidden email]> wrote:

>I have data of mixed types in a data frame - date and numeric, as shown
>
>in summary below. How do I identify the column(s) that is/are not
>numeric, in this case, the first. All I want is to identify the
>column(s) and so that I can remove it/them from the data frame Thanks.
>
>> summary(mydata)
>
>Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2
>1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median
>:2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01
>06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd
>Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max.
>:2825.8
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] 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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying column type

Steven Yen
Thanks much! Yes it does. I will read.

On 2021/4/10 上午 11:33, Jeff Newmiller wrote:

> Does
>
> sapply( mydata, inherits, what = "POSIXt" )
>
> give you any ideas?
>
> On April 9, 2021 8:25:36 PM PDT, Steven Yen <[hidden email]> wrote:
>> I have data of mixed types in a data frame - date and numeric, as shown
>>
>> in summary below. How do I identify the column(s) that is/are not
>> numeric, in this case, the first. All I want is to identify the
>> column(s) and so that I can remove it/them from the data frame Thanks.
>>
>>> summary(mydata)
>> Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2
>> 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median
>> :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01
>> 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd
>> Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max.
>> :2825.8
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying column type

Rui Barradas
In reply to this post by Steven Yen
Hello,

Maybe something like


ok <- sapply(mydata, is.numeric)
mydata <- mydata[ok]


to keep the numeric columns only.


Hope this helps,

Rui Barradas

Às 04:25 de 10/04/21, Steven Yen escreveu:

> I have data of mixed types in a data frame - date and numeric, as shown
> in summary below. How do I identify the column(s) that is/are not
> numeric, in this case, the first. All I want is to identify the
> column(s) and so that I can remove it/them from the data frame Thanks.
>
>> summary(mydata)
>
> Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2
> 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median
> :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01
> 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd
> Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max.
> :2825.8
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Identifying column type

Steven Yen
Thanks. Great idea!

Sent from my iPhone
Beware: My autocorrect is crazy

> On Apr 10, 2021, at 1:37 PM, Rui Barradas <[hidden email]> wrote:
>
> Hello,
>
> Maybe something like
>
>
> ok <- sapply(mydata, is.numeric)
> mydata <- mydata[ok]
>
>
> to keep the numeric columns only.
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 04:25 de 10/04/21, Steven Yen escreveu:
>> I have data of mixed types in a data frame - date and numeric, as shown
>> in summary below. How do I identify the column(s) that is/are not
>> numeric, in this case, the first. All I want is to identify the
>> column(s) and so that I can remove it/them from the data frame Thanks.
>>> summary(mydata)
>> Date Spot Futures Min. :1997-09-01 00:00:00 Min. : 735.1 Min. : 734.2
>> 1st Qu.:2002-10-16 12:00:00 1st Qu.:1120.7 1st Qu.:1122.6 Median
>> :2007-12-01 00:00:00 Median :1301.8 Median :1303.2 Mean :2007-12-01
>> 06:01:27 Mean :1423.1 Mean :1423.6 3rd Qu.:2013-01-16 12:00:00 3rd
>> Qu.:1540.0 3rd Qu.:1546.5 Max. :2018-03-01 00:00:00 Max. :2823.8 Max.
>> :2825.8
>>    [[alternative HTML version deleted]]
>> ______________________________________________
>> [hidden email] 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.

______________________________________________
[hidden email] 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.