Extracting files per types of data file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting files per types of data file

Pedro páramo
Hi all,

For many years I have left R in my daily task but I have returned.

I write to try to get your help on what function look for to program the
next:

My data file is a csv file with lots of data and at the end it ends
with \r\n

Imagine

Name ; Surname; Code; age; CP; \r\n
Oscar ; example ; 1; 42; 4857; \r\n
Maria; Ex3; 2; 33; 879;\r\n
Luz; pruve; 1; 42; 4785; \r\n


I want to run a function that detects all different items in Code in this
case "1" and "2" and output two files named "1.csv or txt" and "2.csv or
txt"  and in this file contain the rows withs all items where Code is 1 and
so on.

The thing is thar I dont know exactly how many different codes are there,
so the programm should "count them" and extract the differents codes and
output the equivalent files of the same kind of code.

It is possible with R? I use big files (and in excel is tedious).

Can you suggest some functions to analyse and to achieve my goal?

Many thanks in advance

        [[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: Extracting files per types of data file

Jim Lemon-4
Hi Pedro,
Will this be sufficient?

ppdf<-read.table(text="Name ; Surname; Code; age; CP; \r\n
Oscar ; example ; 1; 42; 4857; \r\n
Maria; Ex3; 2; 33; 879;\r\n
Luz; pruve; 1; 42; 4785; \r\n",
header=TRUE,sep=";",stringsAsFactors=FALSE)
write.csv(ppdf[ppdf$age==1,1:5],file="ppdf1.csv")
write.csv(ppdf[ppdf$age==2,1:5],file="ppdf2.csv")

Jim

On Sat, May 16, 2020 at 8:36 PM Pedro páramo <[hidden email]> wrote:

>
> Hi all,
>
> For many years I have left R in my daily task but I have returned.
>
> I write to try to get your help on what function look for to program the
> next:
>
> My data file is a csv file with lots of data and at the end it ends
> with \r\n
>
> Imagine
>
> Name ; Surname; Code; age; CP; \r\n
> Oscar ; example ; 1; 42; 4857; \r\n
> Maria; Ex3; 2; 33; 879;\r\n
> Luz; pruve; 1; 42; 4785; \r\n
>
>
> I want to run a function that detects all different items in Code in this
> case "1" and "2" and output two files named "1.csv or txt" and "2.csv or
> txt"  and in this file contain the rows withs all items where Code is 1 and
> so on.
>
> The thing is thar I dont know exactly how many different codes are there,
> so the programm should "count them" and extract the differents codes and
> output the equivalent files of the same kind of code.
>
> It is possible with R? I use big files (and in excel is tedious).
>
> Can you suggest some functions to analyse and to achieve my goal?
>
> Many thanks in advance
>
>         [[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: Extracting files per types of data file

Pedro páramo
Its perfect¡¡¡

Many thanks to all.

El sáb., 16 may. 2020 a las 12:46, Jim Lemon (<[hidden email]>)
escribió:

> Hi Pedro,
> Will this be sufficient?
>
> ppdf<-read.table(text="Name ; Surname; Code; age; CP; \r\n
> Oscar ; example ; 1; 42; 4857; \r\n
> Maria; Ex3; 2; 33; 879;\r\n
> Luz; pruve; 1; 42; 4785; \r\n",
> header=TRUE,sep=";",stringsAsFactors=FALSE)
> write.csv(ppdf[ppdf$age==1,1:5],file="ppdf1.csv")
> write.csv(ppdf[ppdf$age==2,1:5],file="ppdf2.csv")
>
> Jim
>
> On Sat, May 16, 2020 at 8:36 PM Pedro páramo <[hidden email]>
> wrote:
> >
> > Hi all,
> >
> > For many years I have left R in my daily task but I have returned.
> >
> > I write to try to get your help on what function look for to program the
> > next:
> >
> > My data file is a csv file with lots of data and at the end it ends
> > with \r\n
> >
> > Imagine
> >
> > Name ; Surname; Code; age; CP; \r\n
> > Oscar ; example ; 1; 42; 4857; \r\n
> > Maria; Ex3; 2; 33; 879;\r\n
> > Luz; pruve; 1; 42; 4785; \r\n
> >
> >
> > I want to run a function that detects all different items in Code in this
> > case "1" and "2" and output two files named "1.csv or txt" and "2.csv or
> > txt"  and in this file contain the rows withs all items where Code is 1
> and
> > so on.
> >
> > The thing is thar I dont know exactly how many different codes are there,
> > so the programm should "count them" and extract the differents codes and
> > output the equivalent files of the same kind of code.
> >
> > It is possible with R? I use big files (and in excel is tedious).
> >
> > Can you suggest some functions to analyse and to achieve my goal?
> >
> > Many thanks in advance
> >
> >         [[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.
>

        [[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.