Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Benoit Vaillant
Hello, On Tue, Aug 13, 2019 at 01:59:56PM -0400, Christopher W Ryan wrote: > But this assumes that all files have column names in their first row. In > this case, some don't. Any advice how to handle it so that those with > column names and those without are read in and combined properly? It

Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread peter dalgaard
Yes. Also, the original poster said that the files had the same column structure, so there may be stronger heuristics to see whether the first line is a header line. E.g., assuming that the first column is called "ID" (and doesn't have ID as a possible value) use first <- readLines(file, 1)

Re: [R-es] Acceso a elemento de una lista

2019-08-13 Thread Javier Nieto
Hola Tal vez te sirva esto: prueba <- iris prueba <- rbind(prueba, prueba[1:3, ]) n <- 10 nr <- nrow(prueba) prueba <- split(prueba, rep(1:ceiling(nr/n), each=n, length.out=nr)) # Forma 1: lapply(prueba, function(x) { fwrite(x, paste0("file", parent.frame()$i)) print("Guardado.") } ) # Forma 2:

[R-es] Acceso a elemento de una lista

2019-08-13 Thread Andrés Hirigoyen
Buenas tardes, Tengo una lista con 420 data frame (numerados del ID 1 al ID 420, ), como se ve en el str(), cada data frame tiene 45 observaciones de 30 variables: str(lista1) $ 1:'data.frame': 45 obs. of 30 variables:... ¿Cómo puedo generar los 420 objetos diferentes para poder

Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Peter Langfelder
If the data are numeric (or at least some columns are numeric), a brute force solution is to read a file once with header = FALSE, check the relevant column(s) for being numeric, and if they are not numeric, re-read with header = TRUE. Alternatively, if you know the column names (headers)

Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Sarah Goslee
Like Bert, I can't see an easy approach for datasets that have character rather than numeric data. But here's a simple approach for distinguishing files that have possible character headers but numeric data. readheader <- function(filename) { possibleheader <- read.table(filename, nrows=1,

Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Bert Gunter
Are these files of numerics? In other words, how would one know whether the first line of a file of alpha data are headers or not? read.table's Help file contains some info that may or may not be relevant for your files also. Assuming a criterion for distinction, one could simply read the first

[R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Christopher W Ryan
Alas, we spend so much time and energy on data wrangling . . . . I'm given a collection of csv files to work with---"found data". They arose via saving Excel files to csv format. They all have the same column structure, except that some were saved with column names and some were not. I have a

Re: [R] separate and gather functions

2019-08-13 Thread Eric Berger
Chapeau Ista :-) On Tue, Aug 13, 2019 at 4:22 PM Ista Zahn wrote: > How about > > > library(tidyr) > > separate_rows(d, Col2) > Col1 Col2 > 1 Agency A Function1 > 2 Agency A Function2 > 3 Agency A Function3 > 4 Agency A Function4 > 5 Agency B Function2 > 6 Agency B Function4 > 7

Re: [R] Need help with an iteration

2019-08-13 Thread PIKAL Petr
Hi I does not use Deducer so I do not know if it has some features for such task In plain R instead file.names <- dir(pattern = "*.txt") use file.names <- list.files(pattern = "*.txt") for(i in 1:length(file.names)){file <- > read.table(file.names[i],header=TRUE) # Here you want to change

Re: [R] separate and gather functions

2019-08-13 Thread Ista Zahn
How about > library(tidyr) > separate_rows(d, Col2) Col1 Col2 1 Agency A Function1 2 Agency A Function2 3 Agency A Function3 4 Agency A Function4 5 Agency B Function2 6 Agency B Function4 7 Agency C Function1 8 Agency C Function3 9 Agency C Function4 On Mon, Aug 12, 2019 at 11:06 PM

[R] Need help with an iteration

2019-08-13 Thread Neotropical bat risk assessments
Hi all, I am having an issue with trying to run iterations for the same analysis with a list of data sets.  I am assuming I am missing a basic step here. Code I am trying is below.  Not certain if a NEXT call needs to be included somewhere or not. This is run under the Deducer GUI.  I would

Re: [R] Trying to understand how to sort a DF on two columns

2019-08-13 Thread Rui Barradas
Hello, Though good answers were already given, I would like to say something. 1. If you are lazy (typing), use with, if you prefer to play safe, don't. I am lazy many times, but in interactive mode only. 2. I find it better in the long run *not* to take advantage of R's one-liners, they tend