[R] re move row if the column "date_abandoned" has a date in it

David Winsemius dwinsemius at comcast.net
Sun Nov 15 17:50:54 CET 2009


On Nov 15, 2009, at 11:00 AM, frenchcr wrote:

>
>
> Yes they are not in date format, theyre just characters.
>
> the earliest date is 16010000 i originally had one of  0101 00 00  
> (101 years
> BC)...this was a software problem.
>
>> table(nchar(new_data4$date_abandoned))
>
>     2      8
> 315732    263
>
> The 315732 are empty fields i thought.

They are actually 2 characters wide.

> The 263 are dates, i want to remove their rows.

If you want to "remove" the ones that are _not_ 8 characters long, then:

new_data5 <- new_data4[nchar(new_data4$date_abandoned) != 8, ]

or:

new_data5 <- subset(new_data4, date_abandoned != 8)

-- 
David.

>
>
>
> David Winsemius wrote:
>>
>>
>> On Nov 14, 2009, at 8:43 PM, frenchcr wrote:
>>
>>>
>>> sorry David,
>>>
>>> im really new to R (my first week) and appreciate your help. Also I
>>> dont
>>> always know what info to give people on the forum (although im
>>> starting to
>>> catch the drift).
>>>
>>> heres what i get...
>>>
>>> summary(new_data4$date_abandoned)
>>> Min.        1st Qu.    Median     Mean      3rd Qu.
>>> Max.          NA's
>>> 16010000 19980000 20010000 19930000 20040000  20090000   315732
>>
>> So new_data4$data_abandoned is not of type "Date" and is instead a
>> character vector.
>>
>> If you are resisting turning it into a date and want to work with
>> characters, you can, you just need to deal somehow with the items  
>> that
>> are not 8 characters wide. What does 315732 represent? How were we
>> supposed to interpret the starting "date" you gave of "01010000"?
>>
>>> nchar("1010000")
>> [1] 7
>>
>> What does table(nchar(new_data4$date_abandoned)) give you?
>>>
>>>> ls()
>>> [1] "data"      "new_data"  "new_data2" "new_data3" "new_data4"
>>>> small <- head(new_data4, 20)
>>>> dump("small", 20)
>>> Error in dump("small", 20) : cannot write to this connection
>>
>>
>> Well, sorry, I meant to type dump("small", stdout())   ... As per the
>> Posting Guide.
>>
>> -- 
>> David.
>>>
>>> David Winsemius wrote:
>>>>
>>>>
>>>> On Nov 14, 2009, at 5:24 PM, frenchcr wrote:
>>>>
>>>>>
>>>>>
>>>>> I tried the following but it does the opposite of what i want:
>>>>>
>>>>> new_data5 <- subset(new_data4, date_abandoned > "01010000")
>>>>>
>>>>> I want to remove the rows with dates and leave just the rows  
>>>>> without
>>>>> a date.
>>>>>
>>>>> This removes all the rows that dont have a date in the
>>>>> date_abandoned column
>>>>>
>>>>> ...on a positive note, as i did this next...
>>>>>
>>>>> dim(new_data5)
>>>>> [1] 263  80
>>>>>
>>>>> ....i now know that i have 263 dates in that column :)
>>>>>
>>>>> I want to remove the 263 rows with dates and leave just the rows
>>>>> without a
>>>>> date.
>>>>
>>>> Con=me on frenchcr. Stop making us guess. Give us enough  
>>>> information
>>>> to work with. You asked for something which I construed as saying  
>>>> you
>>>> wanted dates greater than the the first day of the year 101. You  
>>>> did
>>>> not address this question.
>>>>
>>>> What do you get with str(new_data4) and
>>>> summary(new_data4$date_abandoned) ? In order to know what sort of
>>>> comparison to use we need to know what the data looks like.
>>>>
>>>> Even better if you offered the output from:
>>>>
>>>> small <- head(new_data4, 20)
>>>> dump("small", 20),
>>>>
>>>> -- 
>>>> David
>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> David Winsemius wrote:
>>>>>>
>>>>>>
>>>>>> On Nov 14, 2009, at 1:21 PM, frenchcr wrote:
>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> I want to go through a column in data called
>>>>>>
>>>>>> Bad name for a data.frame. Fortunes, "dog" and all that.
>>>>>>
>>>>>>> date_abandoned....data["date_abandoned"]....and remove all the
>>>>>>> rows
>>>>>>> that
>>>>>>> have numbers greater than 1,010,000.
>>>>>>
>>>>>> Are you doing archeology? Given what you say next I wondered what
>>>>>> range you were really asking for.
>>>>>>
>>>>>>>
>>>>>>> The dates are in the format 20091114 so i'm just going to treat
>>>>>>> them
>>>>>>> as
>>>>>>> numbers for clean up purposes.
>>>>>>>
>>>>>>>
>>>>>>> I know that i use subset but not sure how to proceed from there.
>>>>>>
>>>>>> subdata <- subset(data, date_abandoned > "01010000"()
>>>>>>
>>>>>>
>>>>>> The problem with > "1010000" is that your specified minimum point
>>>>>> had
>>>>>> an insufficient number of "places" to be in YYYYMMDD format.
>>>>>>
>>>>>> --
>>>>>>
>>>>>> David Winsemius, MD
>>>>>> Heritage Laboratories
>>>>>> 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.
>>>>>>
>>>>>>
>>>>>
>>>>> -- 
>>>>> View this message in context:
>>>>> http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26354446.html
>>>>> Sent from the R help mailing list archive at Nabble.com.
>>>>>
>>>>> ______________________________________________
>>>>> 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.
>>>>
>>>> David Winsemius, MD
>>>> Heritage Laboratories
>>>> 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.
>>>>
>>>>
>>>
>>> -- 
>>> View this message in context:
>>> http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26355689.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> 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.
>>
>> David Winsemius, MD
>> Heritage Laboratories
>> 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.
>>
>>
>
> -- 
> View this message in context: http://old.nabble.com/remove-row-if-the-column-%22date_abandoned%22-has-a-date-in-it-tp26352457p26360384.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list