Sashi Challa
2011-Mar-23 16:03 UTC
[R] Modifying a particular column in a tab-delimited file
Hello R users, Good day!! I was wondering if there is a way in R to read in a particular column from a tab-delimited file, edit it and write it back into the file with all other columns intact. When I say edit I mean just replacing all the values in that column. I know to read a particular column from a file using colClasses option in read.delim() function. Is there any such option to write out a column into an already existing file using write.table() function ?? Thanks for your time -Sashi [[alternative HTML version deleted]]
jim holtman
2011-Mar-23 18:50 UTC
[R] Modifying a particular column in a tab-delimited file
Read the whole file in, modify the column and then write the file back out. On Wed, Mar 23, 2011 at 12:03 PM, Sashi Challa <challa at ohsu.edu> wrote:> Hello R users, > > Good day!! > > I was wondering if there is a way in R to read in a particular column from a tab-delimited file, edit it and write it back into the file with all other columns intact. When I say edit I mean just replacing all the values in that column. > I know to read a particular column from a file using colClasses option in read.delim() function. > Is there any such option to write out a column into an already existing file using write.table() function ?? > > Thanks for your time > > -Sashi > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
Sashi Challa
2011-Mar-23 19:44 UTC
[R] Modifying a particular column in a tab-delimited file
Hi Jim, That is what I ended up doing. Each of my 1000 files has ~1 million rows, and 19 columns and it was taking 85 secs for every file to be just read into R. All I needed to do was replace one column with a particular vector values. So wanted to know if there was a way to do it without reading all the columns. Thanks for your time, Sashi -----Original Message----- From: jim holtman [mailto:jholtman at gmail.com] Sent: Wednesday, March 23, 2011 11:50 AM To: Sashi Challa Cc: r-help at r-project.org Subject: Re: [R] Modifying a particular column in a tab-delimited file Read the whole file in, modify the column and then write the file back out. On Wed, Mar 23, 2011 at 12:03 PM, Sashi Challa <challa at ohsu.edu> wrote:> Hello R users, > > Good day!! > > I was wondering if there is a way in R to read in a particular column from a tab-delimited file, edit it and write it back into the file with all other columns intact. When I say edit I mean just replacing all the values in that column. > I know to read a particular column from a file using colClasses option in read.delim() function. > Is there any such option to write out a column into an already existing file using write.table() function ?? > > Thanks for your time > > -Sashi > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
David Winsemius
2011-Mar-23 19:50 UTC
[R] Modifying a particular column in a tab-delimited file
On Mar 23, 2011, at 3:44 PM, Sashi Challa wrote:> Hi Jim, > > That is what I ended up doing. Each of my 1000 files has ~1 million > rows, and 19 columns and it was taking 85 secs for every file to be > just read into R. > All I needed to do was replace one column with a particular vector > values. So wanted to know if there was a way to do it without > reading all the columns.Learn to use awk?> Thanks for your time, > Sashi > > -----Original Message----- > From: jim holtman [mailto:jholtman at gmail.com] > Sent: Wednesday, March 23, 2011 11:50 AM > To: Sashi Challa > Cc: r-help at r-project.org > Subject: Re: [R] Modifying a particular column in a tab-delimited file > > Read the whole file in, modify the column and then write the file > back out. > > On Wed, Mar 23, 2011 at 12:03 PM, Sashi Challa <challa at ohsu.edu> > wrote: >> Hello R users, >> >> Good day!! >> >> I was wondering if there is a way in R to read in a particular >> column from a tab-delimited file, edit it and write it back into >> the file with all other columns intact. When I say edit I mean just >> replacing all the values in that column. >> I know to read a particular column from a file using colClasses >> option in read.delim() function. >> Is there any such option to write out a column into an already >> existing file using write.table() function ?? >> >> Thanks for your time >> >> -Sashi >David Winsemius, MD West Hartford, CT
jim holtman
2011-Mar-23 21:30 UTC
[R] Modifying a particular column in a tab-delimited file
You would still have to read every file in, extract the column, modify it, put it back in the file in the right place and then write the file out. With a text file that is just a stream of characters, you do not know where a row is unless you read in the entire file. You might want to consider using a database that would allow such an operation, but with a CSV that is what you have to do. For example, how easy would it be to do with a standard text editor? On Wed, Mar 23, 2011 at 3:44 PM, Sashi Challa <challa at ohsu.edu> wrote:> Hi Jim, > > That is what I ended up doing. Each of my 1000 files has ~1 million rows, and 19 columns and it was taking 85 secs for every file to be just read into R. > All I needed to do was replace one column with a particular vector values. So wanted to know if there was a way to do it without reading all the columns. > Thanks for your time, > Sashi > > -----Original Message----- > From: jim holtman [mailto:jholtman at gmail.com] > Sent: Wednesday, March 23, 2011 11:50 AM > To: Sashi Challa > Cc: r-help at r-project.org > Subject: Re: [R] Modifying a particular column in a tab-delimited file > > Read the whole file in, modify the column and then write the file back out. > > On Wed, Mar 23, 2011 at 12:03 PM, Sashi Challa <challa at ohsu.edu> wrote: >> Hello R users, >> >> Good day!! >> >> I was wondering if there is a way in R to read in a particular column from a tab-delimited file, edit it and write it back into the file with all other columns intact. When I say edit I mean just replacing all the values in that column. >> I know to read a particular column from a file using colClasses option in read.delim() function. >> Is there any such option to write out a column into an already existing file using write.table() function ?? >> >> Thanks for your time >> >> -Sashi >> >> >> ? ? ? ?[[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> 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. >> > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?