[R] replacement of dataframe

Steve Miller smiller73 at jhu.edu
Wed May 17 15:12:43 CEST 2006


Or simply: 

sam <- factor(sample(1:3,100,replace=T))
sam <- factor(sam, labels=c("0-10","10-20","20-30"))

Steve Miller


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Petr Pikal
Sent: Wednesday, May 17, 2006 7:19 AM
To: orkun; r-help at stat.math.ethz.ch
Subject: Re: [R] replacement of dataframe

Hi

On 17 May 2006 at 14:51, orkun wrote:

Date sent:      	Wed, 17 May 2006 14:51:43 +0300
From:           	orkun <temiz at deprem.gov.tr>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] replacement of dataframe

> hello
> 
> how can I replace dataframe data with another data ?
> something like:
> 
>  > str(dpr2$eg)
>  Factor w/ 8 levels "1","2","3","4",..:
> 
> I want to replace  "1" with "0-10"

Replace levels attribute of a factor

?levels

x<-factor(sample(1:8,100, replace=T))
x
   [1] 4 6 4 3 7 2 6 1 2 2 2 1 6 8 7 7 4 4 7 5 6 3 3 8 6 2 2 4 8 5 8 
6 3 4 2 1 6 1 4 6 8 4 4 2 7 4 5 2 2 5 5 1 1 6 8 5 5 5 8 5 6 5 2 3 6
  [66] 4 2 6 1 7 5 5 3 4 5 2 5 1 3 2 3 8 4 7 8 4 1 3 6 3 6 7 7 4 4 8 
6 6 5 8
 Levels: 1 2 3 4 5 6 7 8
levels(x)
 [1] "1" "2" "3" "4" "5" "6" "7" "8"
 levels(x)[1]<-"0-10"

HTH
Petr



> 
> regards
> 
> -- 
> Ahmet Temiz
> Jeoloji Müh.
> Afet Ýţleri Genel Müdürlüđü
> Deprem Araţtýrma Dairesi
> Tel: (312) 287 89 51 veya (312) 287 26 80/1547
> Faks: (312) 287 89 51
> E. Posta: temiz at deprem.gov.tr
>  www.deprem.gov.tr
> 
> Ahmet Temiz
> Geological Eng.
> General Directorate of Disaster Affairs
> Earthquake Research Department
> Phone: +90 (312) 287 89 51 or (312) 287 26 80/1547
> Fax: +90 (312) 287 89 51
> E. Mail: temiz at deprem.gov.tr
> www.deprem.gov.tr
> 
> 
> -- 
> This message has been scanned for viruses and\ dangerous
> con...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list