[R] Ps: Reinterpret data without saving it to a file 1st? Check for integer stopping at 1st decimal?

DynV Montrealer dynvec @end|ng |rom gm@||@com
Mon Jul 15 07:36:59 CEST 2024


The answer:
https://statisticsglobe.com/change-classes-data-frame-columns-automatically-r

On Sun, Jul 14, 2024 at 3:16 AM DynV Montrealer <dynvec using gmail.com> wrote:

> A small number of columns in the data I need to work with are strings, the
> rest numbers.  I'm using read_excel() from the readxl package to get the
> data ; right after it, the string columns are of type chr and the rest num.
> I'm tasked with finding out which columns are integers. From an advice, I
> tried saving the spreadsheet content into a CSV then loading that, which
> works like a charm ; the chr columns are the same but now a large portion
> of num is now instead int. Is there a way to skip writing and reading a CSV
> and get the same transformation? Perhaps some way to break the spreadsheet
> data (eg XLdata <- read_excel(...)), then put it back together without any
> writing to a file (eg XLdataReformed <- reform(XLdata)) ?
>
> In addition, from is.integer() documentation I ran
>
> > is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x -
> round
> > (x)) < tol
>
> and I'm now trying to have it stop at the 1st decimal content of a column.
> Someone advised me to use break and I scripted
>
> > is_integer = TRUE for (current_row in seq_along(data$column)) { if (!
> > is.wholenumber(data$column[current_row])) { is_integer = FALSE break; } }
>
> but I'm wondering if there's something better to check if a column is
> entirely made of integers.
>
> Thank you kindly for your help
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list