Re: [R] altering identity column

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Mon, 18 Apr 2011 09:56:39 -0400

On Apr 18, 2011, at 9:02 AM, Bodnar Laszlo EB_HU wrote:

> Hi there,
>
> I have a huge dataframe containing 70,000 observations.
>
> I have filtered this dataframe (let it's name be
> "transformed_dataframe") as I wanted to select only those
> observations which are greater than or equal to 60,001 regarding the
> very first identity column.

I am guessing that what you want is something like

dfrm2 <- transformed_dataframe[rownames(transformed_dataframe) >= "60001" , ]

Or perhaps (if you carrying the thousands separator into the rownames:

dfrm2 <- transformed_dataframe[rownames(transformed_dataframe) >= "60,001" , ]

Or if you are using spaces then:

dfrm2 <- transformed_dataframe[rownames(transformed_dataframe) >= "60 001" , ]

This would involve much less guessing if you offered the results of:

  str(transformed_dataframe)

>
> So I have a transformed dataframe now including 10,000 obeservations
> (from 60,001 - to 70,000) and if you send
> "head(transformed_dataframe)" into R it looks like this:
>
> variable1 variable2
> variable3 variable4 ...
> 60
> 001
> ... ... ... ...
> 60
> 002
> ... ... ... ...
> 60
> 003
> ... ... ... ...
> 60
> 004
> ... ... ... ...
> 60
> 005
> ... ... ... ...
>
> Sending "tail(transformed_dataframe)" into R it is going to be
> something like:
>
> variable1 variable2
> variable3 variable4 ...
> 69
> 996
> ... ... ... ...
> 69
> 997
> ... ... ... ...
> 69
> 998
> ... ... ... ...
> 69
> 999
> ... ... ... ...
> 70
> 000
> ... ... ... ...
>
>
> Now is there a quick way to alter this indexing of rows in case of
> my "transformed_dataframe"? I mean, I would like to get indices 1,
> 2, 3, etc... instead of 60 001, 60 002, 60 003 etc...

rownames(transformed_dataframe) <- 1:10000

>
> So by sending "head(transformed_dataframe)" and
> "tail(transformed_dataframe)" I would like to see:
>
> variable1 variable2
> variable3 variable4 ...
> 1
> ... ... ... ...
> 2
> ... ... ... ...
> 3
> ... ... ... ...
> 4
> ... ... ... ...
> 5
> ... ... ... ...
>
> and
>
> variable1 variable2
> variable3 variable4 ...
> 9
> 996
> ... ... ... ...
> 9
> 997
> ... ... ... ...
> 9
> 998
> ... ... ... ...
> 9
> 999
> ... ... ... ...
> 10
> 000
> ... ... ... ...
>
> Thank you very much, best regards,
>
> Laszlo
> ______________________________________________________________________________________________

David Winsemius, MD
West Hartford, CT



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. Received on Mon 18 Apr 2011 - 13:58:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Apr 2011 - 14:00:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive