Hi, I am just starting using R. Hence, sorry for asking probably rather easy questions. I used "read.table" to bring an .txt Table to R. Unfortunately the columns do not have the same length. I tried "fill=TRUE", to fill the blank space with "na". In a certain kind of way it worked, but befor filling the spaces it moved data from later columns to the first: 1 a b c 1 a b c 2 a b c 2 a b c 3 a b c 3 a b c 4 b c 4 b c NA 5 c 5 c NA NA What is my mistake? Thank you Sebastian -- *************************************************************************************************************** Dipl. Biol. Sebastian Krug PhD - student IFM - GEOMAR Leibniz Institute of Marine Sciences Research Division 2 - Marine Biogeochemistry D?sternbrooker Weg 20 D - 24105 Kiel Germany Tel.: +49 431 600-4282 Fax.: +49 431 600-4446 email: skrug at ifm-geomar.de
How are you sure it moved the data? What is the column separator that you have? Is it just 'white space' as opposed to a tab or comma? It you have a CSV file with a separator, the system knows where the columns are. If it sees 'a b c' and then 'a c' as the next row, 'c' will be in column 2 even though you thought 'b' was missing. On Thu, Mar 26, 2009 at 11:39 AM, skrug <skrug at ifm-geomar.de> wrote:> Hi, > > I am just starting using R. Hence, sorry for asking probably rather easy > questions. > > I used "read.table" to bring an .txt Table to R. Unfortunately the columns > do not have the same length. I tried "fill=TRUE", to fill the blank space > with "na". In a certain kind of way it worked, but befor filling the spaces > it moved data from later columns to the first: > > 1 ? ?a ? b ? c ? ? ? ? ? ? ? ? ?1 ? a ? b ? c > 2 ? a ? b ? ? ?c ? ? ? ? ? ? ? ? ?2 ? a ? b ? c ?3 ? a ? b ? ? ?c > ? ? ? ? 3 ? a ? b ? ?c 4 ? ? ?b ? ? ?c ? ? ? ? ? ? ? ? ? ? 4 ? b ? c ? ?NA > 5 ? ? ? ? ? ?c ? ? ? ? ? ? ? ? ? ? ? 5 ? c ? NA NA > > What is my mistake? > > Thank you > Sebastian > > > -- > *************************************************************************************************************** > > Dipl. Biol. Sebastian Krug > PhD - student > IFM - GEOMAR > Leibniz Institute of Marine Sciences > Research Division 2 - Marine Biogeochemistry > D?sternbrooker Weg 20 > D - 24105 Kiel > Germany > > Tel.: +49 431 600-4282 > Fax.: +49 431 600-4446 > email: skrug at ifm-geomar.de > > ______________________________________________ > 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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Hi r-help-bounces at r-project.org napsal dne 26.03.2009 16:39:18:> Hi, > > I am just starting using R. Hence, sorry for asking probably rather easy> questions. > > I used "read.table" to bring an .txt Table to R. Unfortunately the > columns do not have the same length. I tried "fill=TRUE", to fill the > blank space with "na". In a certain kind of way it worked, but befor > filling the spaces it moved data from later columns to the first: > > 1 a b c 1 a b c > 2 a b c 2 a b c > 3 a b c 3 a b c > 4 b c 4 b c NA > 5 c 5 c NA NAHow do you know that c is in third column? If you can expect fixed width fields try read.fwf but if there is nothing what separates fields and they have variable length it would be quite difficult. Maybe to read each line and then to use some regexpr function no properly divide each line into appropriate columns. But maybe somebody will come with better idea. Regards Petr> > What is my mistake? > > Thank you > Sebastian > > > -- >***************************************************************************************************************> > Dipl. Biol. Sebastian Krug > PhD - student > IFM - GEOMAR > Leibniz Institute of Marine Sciences > Research Division 2 - Marine Biogeochemistry > D?sternbrooker Weg 20 > D - 24105 Kiel > Germany > > Tel.: +49 431 600-4282 > Fax.: +49 431 600-4446 > email: skrug at ifm-geomar.de > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.