[R] about change columns for specific rows

ruipbarradas at sapo.pt ruipbarradas at sapo.pt
Sat Jan 30 19:43:17 CET 2016


Sorry, there's a mistake, there's a missing comma, it should be

df[df$date >= '2012-01-01'& df$date <= '2013-12-31', ]$A

Rui Barradas
 

Citando ruipbarradas at sapo.pt:

> Hello,
>
> Try
>
> df[df$date >= '2012-01-01'& df$date <= '2013-12-31']$A = etc
>
> Hope this helps,
>
> Rui Barradas
>  
>
> Citando lily li <chocold12 at gmail.com>:
>> Hi R users,
>>
>> I have a data frame, and I generate a date column like this:
>> df$date = seq(as.Date('2012-01-01'), as.Date('2014-12-31'))
>>
>> df
>> A  B  C
>> 1  2   1
>> 2  2   3
>> 3  2   4
>>
>> So the data frame has 4 columns now. But when I want to change the values
>> of column A for specific dates, such as 2012-01-01 to 2013-12-31, I use the
>> code below:
>> df[date >= '2012-01-01'&date <= '2013-12-31']$A =
>> df[date >= '2012-01-01'&date <= '2013-12-31']$A +2
>>
>> But it does not work, the date I generate seems not effective. What is the
>> problem? Thanks for your help.
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.htmland provide commented,
>> minimal, self-contained, reproducible code.
>
>  
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.htmland provide commented,  
> minimal, self-contained, reproducible code.

 

	[[alternative HTML version deleted]]



More information about the R-help mailing list