Re: [R] remove a row

2019-11-28 Thread Bert Gunter
Of course! Use regexec() and regmatches()

>
regmatches(dat$varx,regexec("(^[[:digit:]]{1,3})([[:alpha:]]{1,2})([[:digit:]]{1,5}$)",dat$varx))
[[1]]
[1] "9F209" "9" "F" "209"

[[2]]
character(0)

[[3]]
[1] "2F250" "2" "F" "250"

[[4]]
character(0)

[[5]]
character(0)

[[6]]
character(0)

[[7]]
character(0)

[[8]]
[1] "121FL50" "121" "FL"  "50"

The list components are character(0) for no match, otherwise a character
vector with the whole text entry first, then the 1st, 2nd, and 3rd strings
matching the 1st, 2nd, and 3rd parenthesized subexpressions of the pattern.
These correspond to area code, region code, and your 3rd numeric of course.
I leave it to you to extract what you want from this list, e.g via lapply().

For details, see the Help pages for the two functions.

-- Bert

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] remove a row

2019-11-28 Thread Ashta
Thank you so much Bert.

Is it possible to split the varx into  three ( area code, region and
the numeric part)as a separate variable

On Thu, Nov 28, 2019 at 7:31 PM Bert Gunter  wrote:
>
> Use regular expressions.
>
> See ?regexp  and ?grep
>
> Using your example:
>
> > grep("^[[:digit:]]{1,3}[[:alpha:]]{1,2}[[:digit:]]{1,5}$",dat$varx,value = 
> > TRUE)
> [1] "9F209"   "2F250"   "121FL50"
>
> Cheers,
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and 
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Thu, Nov 28, 2019 at 3:17 PM Ashta  wrote:
>>
>> Hi all,  I want to remove a row based on a condition in one of the
>> variables from a data frame.
>> When we split this string it should be composed of 3-2- 5 format (3
>> digits numeric, 2 characters and 5 digits  numeric).  Like
>> area code -region-numeric. The max length of the area code should be
>> 3, the  max length of region be should be 2,  followed by a max length
>> of  5  numeric digits.  The are code  can  be 1 digit, or 2 digits or
>> 3 digits  but not more than three digits.  So  the  max length of this
>> variable is 10.  Anything outside of this pattern should be excluded.
>> As an example
>>
>> dat <-read.table(text=" rown  varx
>> 1   9F209
>> 2  FL250
>> 3  2F250
>> 4  102250
>> 5  102FL
>> 6   102
>> 7  1212FL250
>> 8  121FL50",header=TRUE,stringsAsFactors=F)
>>
>> 1  9F209   # keep
>> 2  FL250   # remove, no area code
>> 3   2F250  # keep
>> 4  102250 # remove , no region code
>> 5  102FL   # remove , no numeric after region code
>> 6   102  # remove ,  no region code and numeric
>> 7  1212FL250  #remove, area code is more than three digits
>> 8  121FL50  # Keep
>>
>> The desired output should be
>> 1   9F209
>> 3   2F250
>> 8  121FL50
>>
>> How do I do this in an efficient way?
>>
>> Thank you in advance
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] remove a row

2019-11-28 Thread Bert Gunter
Use regular expressions.

See ?regexp  and ?grep

Using your example:

> grep("^[[:digit:]]{1,3}[[:alpha:]]{1,2}[[:digit:]]{1,5}$",dat$varx,value
= TRUE)
[1] "9F209"   "2F250"   "121FL50"

Cheers,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, Nov 28, 2019 at 3:17 PM Ashta  wrote:

> Hi all,  I want to remove a row based on a condition in one of the
> variables from a data frame.
> When we split this string it should be composed of 3-2- 5 format (3
> digits numeric, 2 characters and 5 digits  numeric).  Like
> area code -region-numeric. The max length of the area code should be
> 3, the  max length of region be should be 2,  followed by a max length
> of  5  numeric digits.  The are code  can  be 1 digit, or 2 digits or
> 3 digits  but not more than three digits.  So  the  max length of this
> variable is 10.  Anything outside of this pattern should be excluded.
> As an example
>
> dat <-read.table(text=" rown  varx
> 1   9F209
> 2  FL250
> 3  2F250
> 4  102250
> 5  102FL
> 6   102
> 7  1212FL250
> 8  121FL50",header=TRUE,stringsAsFactors=F)
>
> 1  9F209   # keep
> 2  FL250   # remove, no area code
> 3   2F250  # keep
> 4  102250 # remove , no region code
> 5  102FL   # remove , no numeric after region code
> 6   102  # remove ,  no region code and numeric
> 7  1212FL250  #remove, area code is more than three digits
> 8  121FL50  # Keep
>
> The desired output should be
> 1   9F209
> 3   2F250
> 8  121FL50
>
> How do I do this in an efficient way?
>
> Thank you in advance
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


[R] remove a row

2019-11-28 Thread Ashta
Hi all,  I want to remove a row based on a condition in one of the
variables from a data frame.
When we split this string it should be composed of 3-2- 5 format (3
digits numeric, 2 characters and 5 digits  numeric).  Like
area code -region-numeric. The max length of the area code should be
3, the  max length of region be should be 2,  followed by a max length
of  5  numeric digits.  The are code  can  be 1 digit, or 2 digits or
3 digits  but not more than three digits.  So  the  max length of this
variable is 10.  Anything outside of this pattern should be excluded.
As an example

dat <-read.table(text=" rown  varx
1   9F209
2  FL250
3  2F250
4  102250
5  102FL
6   102
7  1212FL250
8  121FL50",header=TRUE,stringsAsFactors=F)

1  9F209   # keep
2  FL250   # remove, no area code
3   2F250  # keep
4  102250 # remove , no region code
5  102FL   # remove , no numeric after region code
6   102  # remove ,  no region code and numeric
7  1212FL250  #remove, area code is more than three digits
8  121FL50  # Keep

The desired output should be
1   9F209
3   2F250
8  121FL50

How do I do this in an efficient way?

Thank you in advance

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] remove duplicated row according to NA condition

2014-05-29 Thread jeff6868
Yes, this is the good one Arun! Thank you very much. 
I tried each solution but yours was the best. It works well.
Thanks anyway for all your replies!






--
View this message in context: 
http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362p4691422.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] remove duplicated row according to NA condition

2014-05-28 Thread jeff6868
Hi everybody,

I have a little problem in my R-code which seems be easy to solve, but I
wasn't able to find the solution by myself for the moment.

Here's an example of the form of my data:

data -
data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA))

I would like to remove duplicated data based on the first two columns
(col1,col2), but in both cases here, I would like to remove the duplicated
row which is equal to NA in col3.

Here's the data.frame I would like to obtain:

data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002))

I've been trying to mix duplicated() with is.na() but it doesn't work yet.

Can someone tell me the best and easiest way to do this?

Thanks a lot!







--
View this message in context: 
http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] remove duplicated row according to NA condition

2014-05-28 Thread K. Elo
Hi!

How about trying this:

data[ data$col1!=data$col2  !is.na(data$col3), ]

  col1 col2  col3
2a1 ST001
3b2 ST002

HTH, Kimmo


28.05.2014 15:35, jeff6868 wrote:
 Hi everybody,
 
 I have a little problem in my R-code which seems be easy to solve, but I
 wasn't able to find the solution by myself for the moment.
 
 Here's an example of the form of my data:
 
 data -
 data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA))
 
 I would like to remove duplicated data based on the first two columns
 (col1,col2), but in both cases here, I would like to remove the duplicated
 row which is equal to NA in col3.
 
 Here's the data.frame I would like to obtain:
 
 data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002))
 
 I've been trying to mix duplicated() with is.na() but it doesn't work yet.
 
 Can someone tell me the best and easiest way to do this?
 
 Thanks a lot!
 
 
 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.


__
R-help@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.


Re: [R] remove duplicated row according to NA condition

2014-05-28 Thread William Dunlap
It would help if you said what you want done when none or all or some
of the col1-col2 duplicates have NA's in the col3.  E.g., what do you
want the function to do for the following input?

 data2 - data.frame(col1=c(a,a,a,b,b,c,c,d,d,e),
col2=c(1,1,1,2,2,3,3,4,4,5),
col3=c(A1,NA,A3,NA,B2,C1,C2,NA,NA,NA))
 data2
   col1 col2 col3
1 a1   A1
2 a1 NA
3 a1   A3
4 b2 NA
5 b2   B2
6 c3   C1
7 c3   C2
8 d4 NA
9 d4 NA
10e5 NA

(You may want it to return a data.frame or you may want the function
to stop because the data is not considered legal, but you should
decide what it should do.)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, May 28, 2014 at 5:35 AM, jeff6868
geoffrey_kl...@etu.u-bourgogne.fr wrote:
 Hi everybody,

 I have a little problem in my R-code which seems be easy to solve, but I
 wasn't able to find the solution by myself for the moment.

 Here's an example of the form of my data:

 data -
 data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA))

 I would like to remove duplicated data based on the first two columns
 (col1,col2), but in both cases here, I would like to remove the duplicated
 row which is equal to NA in col3.

 Here's the data.frame I would like to obtain:

 data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002))

 I've been trying to mix duplicated() with is.na() but it doesn't work yet.

 Can someone tell me the best and easiest way to do this?

 Thanks a lot!







 --
 View this message in context: 
 http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.

__
R-help@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.


Re: [R] remove duplicated row according to NA condition

2014-05-28 Thread arun


Hi,
May be this helps:
data1 - data[with(data, order(col1, col2,1*is.na(col3))),]
 data1[!duplicated(data1[,1:2]),]
A.K.


On Wednesday, May 28, 2014 11:28 AM, jeff6868 
geoffrey_kl...@etu.u-bourgogne.fr wrote:
Hi everybody,

I have a little problem in my R-code which seems be easy to solve, but I
wasn't able to find the solution by myself for the moment.

Here's an example of the form of my data:

data -
data.frame(col1=c(a,a,b,b),col2=c(1,1,2,2),col3=c(NA,ST001,ST002,NA))

I would like to remove duplicated data based on the first two columns
(col1,col2), but in both cases here, I would like to remove the duplicated
row which is equal to NA in col3.

Here's the data.frame I would like to obtain:

data2 - data.frame(col1=c(a,b),col2=c(1,2),col3=c(ST001,ST002))

I've been trying to mix duplicated() with is.na() but it doesn't work yet.

Can someone tell me the best and easiest way to do this?

Thanks a lot!







--
View this message in context: 
http://r.789695.n4.nabble.com/remove-duplicated-row-according-to-NA-condition-tp4691362.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.

__
R-help@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.


[R] Remove a row containing a specific value for a column

2013-04-07 Thread Beatriz González Domínguez
Dear all,

Could anyone help me with the following?

DATA - data.frame(rbind(c(Red1, 1, 1, 1), c(Blue1, 1, 1, 1), c(Red2, 1, 
1, 1), c(Red3, 1, 1, 1)))
colnames(DATA) - c(A, B,C, D)

#Option 1
DATA - DATA[-2, ] #Same result I would like to achieve with Option 2

#Option 2 - I would like to do it in this way. Do you know how it could be done?
#DATA - THE CODE WOULD SAY (Remove the row which contains the value Blue1 in 
column A)

Many thanks!

Bea
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Remove a row containing a specific value for a column

2013-04-07 Thread arun
Hi,
DATA[DATA$A!=Blue1,]
# A B C D
#1 Red1 1 1 1
#3 Red2 1 1 1
#4 Red3 1 1 1
#or
DATA[!grepl(Blue1,DATA$A),]
# A B C D
#1 Red1 1 1 1
#3 Red2 1 1 1
#4 Red3 1 1 1
A.K.




- Original Message -
From: Beatriz González Domínguez aguitatie...@hotmail.com
To: r-help@r-project.org; R Help r-help-boun...@r-project.org
Cc: 
Sent: Sunday, April 7, 2013 2:31 PM
Subject: [R] Remove a row containing a specific value for a column

Dear all,

Could anyone help me with the following?

DATA - data.frame(rbind(c(Red1, 1, 1, 1), c(Blue1, 1, 1, 1), c(Red2, 1, 
1, 1), c(Red3, 1, 1, 1)))
colnames(DATA) - c(A, B,C, D)

#Option 1
DATA - DATA[-2, ] #Same result I would like to achieve with Option 2

#Option 2 - I would like to do it in this way. Do you know how it could be done?
#DATA - THE CODE WOULD SAY (Remove the row which contains the value Blue1 in 
column A)

Many thanks!

Bea
    [[alternative HTML version deleted]]

__
R-help@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.


__
R-help@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.


Re: [R] remove last row of a data frame

2012-12-12 Thread e-letter
On 12/12/2012, Daniel Nordlund djnordl...@frontier.com wrote:
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of e-letter
 Sent: Tuesday, December 11, 2012 11:45 PM
 To: r-help@r-project.org
 Subject: [R] remove last row of a data frame

 Readers,

 For a data set 'a':

 1
 2
 3
 4

 Please what is the syntax to remove the last row and create a new object
 'b':

 1
 2
 3

 Thanks.


 If by data set a you mean a data frame called a, then something like this
 should work:

 b - a[-nrow(a),]

 If you haven't already read the manual, An Introduction to R, that ships
 with every copy of R, then now is the time.


Thanks, couldn't find quickly the relevant section in the html
document, but within R, the command 'nrow' is relevant.

__
R-help@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.


Re: [R] remove last row of a data frame

2012-12-12 Thread Greg Snow
Another option (better or worse probably depends on many things) is to use:

b - head(a, -1)


On Wed, Dec 12, 2012 at 1:14 AM, e-letter inp...@gmail.com wrote:

 On 12/12/2012, Daniel Nordlund djnordl...@frontier.com wrote:
  -Original Message-
  From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org
 ]
  On Behalf Of e-letter
  Sent: Tuesday, December 11, 2012 11:45 PM
  To: r-help@r-project.org
  Subject: [R] remove last row of a data frame
 
  Readers,
 
  For a data set 'a':
 
  1
  2
  3
  4
 
  Please what is the syntax to remove the last row and create a new object
  'b':
 
  1
  2
  3
 
  Thanks.
 
 
  If by data set a you mean a data frame called a, then something like this
  should work:
 
  b - a[-nrow(a),]
 
  If you haven't already read the manual, An Introduction to R, that
 ships
  with every copy of R, then now is the time.
 

 Thanks, couldn't find quickly the relevant section in the html
 document, but within R, the command 'nrow' is relevant.

 __
 R-help@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.




-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

[[alternative HTML version deleted]]

__
R-help@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.


[R] remove last row of a data frame

2012-12-11 Thread e-letter
Readers,

For a data set 'a':

1
2
3
4

Please what is the syntax to remove the last row and create a new object 'b':

1
2
3

Thanks.

--
R2151

__
R-help@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.


Re: [R] remove last row of a data frame

2012-12-11 Thread Daniel Nordlund
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of e-letter
 Sent: Tuesday, December 11, 2012 11:45 PM
 To: r-help@r-project.org
 Subject: [R] remove last row of a data frame
 
 Readers,
 
 For a data set 'a':
 
 1
 2
 3
 4
 
 Please what is the syntax to remove the last row and create a new object
 'b':
 
 1
 2
 3
 
 Thanks.
 

If by data set a you mean a data frame called a, then something like this 
should work:

b - a[-nrow(a),]

If you haven't already read the manual, An Introduction to R, that ships with 
every copy of R, then now is the time.


hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
 

__
R-help@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.


[R] remove a row from a dataframe, row names disappear

2010-02-05 Thread Euan Reavie
I find this odd because it doesn't appear to happen in larger datasets. I
have the following data set ENV with the first column set as row.names:

 ENV
 TPlog
001S29H  0.601
002S42H  0.602
003S43S  0.779
004S43S  0.702
005S51H  0.978
006S52P  2.718

If I apply  ENV - ENV[-1,]  # remove first row of data (right?)
...ENV comes back as:

[1] 0.602 0.779 0.702 0.978 2.718

So I am losing the row name info. I also notice that, if the first two
values in the TPlog column are the same, both values are removed! What's
going on, and why does this same thing not happen in more complex datasets
with more than one column of values?

Many thanks - Euan.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] remove a row from a dataframe, row names disappear

2010-02-05 Thread Sarah Goslee
You're not only removing a row of data, you are invoking the default
behavior of subset, which is to collapse the subsetted result to the
smallest possible type, which in this case is a vector. Vectors have
no rows, and thus no row names.

You need the drop=FALSE argument, as in
ENV - ENV[-1, , drop=FALSE]

Sarah

On Fri, Feb 5, 2010 at 9:44 AM, Euan Reavie euan.rea...@gmail.com wrote:
 I find this odd because it doesn't appear to happen in larger datasets. I
 have the following data set ENV with the first column set as row.names:

 ENV
         TPlog
 001S29H  0.601
 002S42H  0.602
 003S43S  0.779
 004S43S  0.702
 005S51H  0.978
 006S52P  2.718

 If I apply  ENV - ENV[-1,]  # remove first row of data (right?)
 ...ENV comes back as:

 [1] 0.602 0.779 0.702 0.978 2.718

 So I am losing the row name info. I also notice that, if the first two
 values in the TPlog column are the same, both values are removed! What's
 going on, and why does this same thing not happen in more complex datasets
 with more than one column of values?

 Many thanks - Euan.


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

__
R-help@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.


Re: [R] remove a row from a dataframe, row names disappear - solution

2010-02-05 Thread Euan Reavie
Thank you Sarah.I'm glad it was a quick fix:

On Fri, Feb 5, 2010 at 8:50 AM, Sarah Goslee  wrote:

 You're not only removing a row of data, you are invoking the default
 behavior of subset, which is to collapse the subsetted result to the
 smallest possible type, which in this case is a vector. Vectors have
 no rows, and thus no row names.

 You need the drop=FALSE argument, as in
 ENV - ENV[-1, , drop=FALSE]

 Sarah

 On Fri, Feb 5, 2010 at 9:44 AM, Euan Reavie euan.rea...@gmail.com wrote:
  I find this odd because it doesn't appear to happen in larger datasets. I
  have the following data set ENV with the first column set as row.names:
 
  ENV
  TPlog
  001S29H  0.601
  002S42H  0.602
  003S43S  0.779
  004S43S  0.702
  005S51H  0.978
  006S52P  2.718
 
  If I apply  ENV - ENV[-1,]  # remove first row of data (right?)
  ...ENV comes back as:
 
  [1] 0.602 0.779 0.702 0.978 2.718
 
  So I am losing the row name info. I also notice that, if the first two
  values in the TPlog column are the same, both values are removed! What's
  going on, and why does this same thing not happen in more complex
 datasets
  with more than one column of values?
 
  Many thanks - Euan.


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




-- 

* The opinions expressed in this message do, in fact, represent the opinions
of my employers, their families, and everybody within a 10 mile radius.

[[alternative HTML version deleted]]

__
R-help@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.


[R] Remove zero row from data.frame

2007-10-05 Thread Rees, David
Hi,

Sorry that this is such a basic question, but I am having trouble with
the following.

I would like to remove all rows where the data is all zeros in a
data.frame such as the following

 x
 dateabc
1  2007.09.25 99.89844 100.0586 100.0840
4  2007.09.26 99.89844 100.0586 100.0801
7  2007.09.27  0.0   0.   0.
10 2007.09.28 99.89648 100.0391 100.0664
13 2007.10.01 99.88672 100.0254 100.0566

i.e. in this example remove the 3rd row. 

There could several, or no row with zeros, and in this example there are
only 4 columns, but in general there are several hundred (so hopefully
no typing of a, b, c or x$a, x$b etc.)

Many thanks in advance for any help.

Regards,
D

__
R-help@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.


Re: [R] Remove zero row from data.frame

2007-10-05 Thread Uwe Ligges


Rees, David wrote:
 Hi,
 
 Sorry that this is such a basic question, but I am having trouble with
 the following.
 
 I would like to remove all rows where the data is all zeros in a
 data.frame such as the following
 
 x
  dateabc
 1  2007.09.25 99.89844 100.0586 100.0840
 4  2007.09.26 99.89844 100.0586 100.0801
 7  2007.09.27  0.0   0.   0.
 10 2007.09.28 99.89648 100.0391 100.0664
 13 2007.10.01 99.88672 100.0254 100.0566

Just one example:

x[rowSums(x[,-1]^2)  0, ]

Uwe Ligges


 i.e. in this example remove the 3rd row. 
 
 There could several, or no row with zeros, and in this example there are
 only 4 columns, but in general there are several hundred (so hopefully
 no typing of a, b, c or x$a, x$b etc.)
 
 Many thanks in advance for any help.
 
 Regards,
 D
 
 __
 R-help@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.

__
R-help@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.