[R] a function more appropriate than 'sapply'?
emorway
emorway at usgs.gov
Sat Jan 26 19:43:42 CET 2013
I'm wondering if I need to use a function other than sapply as the following
line of code runs indefinitely (or > 30 min so far) and uses up all 16Gb of
memory on my machine for what seems like a very small dataset (data attached
in a txt file wells.txt
<http://r.789695.n4.nabble.com/file/n4656723/wells.txt> ). The R code is:
wells<-read.table("c:/temp/wells.txt",col.names=c("name","plc_hldr"))
wells2<-wells[sapply(wells[,1],function(x)length(strsplit(as.character(x),
"_")[[1]])==2),]
The 2nd line of R code above gets bogged down and takes all my RAM with it:
<http://r.789695.n4.nabble.com/file/n4656723/memory_loss.png>
I'm simply trying to extract all of the lines of data that have a single "_"
in the first column and place them into a dataset called "wells2". If that
were to work, I then want to extract the lines of data that have two "_" and
put them into a separate dataset, say "wells3". Is there a better way to do
this than the one-liner above?
-Eric
--
View this message in context: http://r.789695.n4.nabble.com/a-function-more-appropriate-than-sapply-tp4656723.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list