[R] Filling Empty Column with String in read.table

Henrique Dallazuanna wwwhsd at gmail.com
Thu Sep 17 13:26:04 CEST 2009


Try this after read the data file:

dat[is.na(dat[,5]),5] <- '-'

On Thu, Sep 17, 2009 at 3:33 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
> I have a data file that looks like this.
>
> __DATA__
> D7KAR5Z02F447V  176 G   0.22
> D7KAR5Z02J3WLG  94  A   1.05    29
> D7KAR5Z02F4K6L  198 a   0.13
> D7KAR5Z02J4SYO  67  C   0.95    28
> D7KAR5Z02J4SYO  83  C   1.01    29
> D7KAR5Z02J4SYO  97  T   0.13
> D7KAR5Z02J4SYO  166 A   0.94    27
>
>
> I want the rows where the last column has no-entry to be filled
> with "-".
>
> Is there a way to do it with read.table?
> I don't find any option to do it with read.table.
>
> This only fill the empty 5th column with blank.
>
> dat <- read.table("myfile.txt",na.strings="-",header=FALSE,fill=T);
>
> G.V.
>
> ______________________________________________
> 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




More information about the R-help mailing list