[R] obtaining a true/false vector with combination of strsplit, length, unlist,

Sarah Goslee sarah.goslee at gmail.com
Sat Feb 11 22:58:24 CET 2012


You are so very close:
> sapply(edm[,1], function(x)length(strsplit(as.character(x), "_")[[1]]) == 3)
[1] FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE

Thanks for providing a small reproducible example. dput() tends
to work better for than than textConnection(), because many email
clients add arbitrary newlines, messing up the text formatting.

Sarah

On Sat, Feb 11, 2012 at 4:51 PM, emorway <emorway at usgs.gov> wrote:
> edm<-read.table(textConnection("WELLID        X_GRID Y_GRID LAYER ROW COLUMN
> SPECIES CALCULATED     OBSERVED
> w301_3          4428.       1389     2   6     18       1       3558
> 6490.
> w304_12         4836.       6627     2  27     20       1       3509
> 3228.
> 02_10_12080    3.6125E+04  13875     1  56    145       1       2774
> -999.0
> 02_10_12080    3.6125E+04  13875     1  56    145       1       2774
> -999.0
> 02_10_12081    3.6375E+04  13875     1  56    146       1       3493
> -999.0
> 02_10_12092    3.9125E+04  13875     1  56    157       1       4736
> -999.0
> w305_12         2962.       7326     2  30     12       1       4575
> 5899."),header=T)
> closeAllConnections()



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list