Amelia Livington
2010-Feb-12 11:31 UTC
[R] how to read csv file having variables unequal column sizes
Dear R helpers Suppose e.g. I have a csv file having three variables defined and each of these variables have data items of say 40, 50, 45 length. When I open this csv file in 'R', I get 10 trailing 'NA's under first column and 5 'NA' s in case of 3rd column. How do I get rid of these NA's s.t. when I read the first column, there should be only 40 data items, 2nd column should have only 50 data items and last one should have 45 data items as in the original csv file. Thanking in advance Amelia [[alternative HTML version deleted]]
Henrique Dallazuanna
2010-Feb-12 11:48 UTC
[R] how to read csv file having variables unequal column sizes
Try this: #DF <- read.table(...) lapply(DF, function(col)col[!is.na(col)]) On Fri, Feb 12, 2010 at 9:31 AM, Amelia Livington <amelia_livington at yahoo.com> wrote:> Dear R helpers > > Suppose e.g. I have a csv file having three variables defined and each of these variables have data items of say 40, 50, 45 length. When I open this csv?file in 'R', I get 10 trailing 'NA's under first column and 5 'NA' s in case of 3rd column. > > How do I get rid of these NA's s.t. when I read the first column, there should be only 40 data items, 2nd column should have only 50 data items and last one should have 45 data items as in the original csv file. > > Thanking in advance > > Amelia > > > > > > ? ? ? ?[[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. > >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O