Re: [R] Creating a column based on data in another column

2009-08-12 Thread Mehdi Khan
Hey guys, I have the same question, except in reverse: if we had letter
classifications and wanted to assign numerical values to them (the case I
stated previously except the other way around) how would we do that?  I am
trying to use the recode function in the car package but not having any
luck..

Thank you!!

On Fri, Jul 31, 2009 at 12:04 PM, Mehdi Khan mwk...@ucdavis.edu wrote:

 hello all,

 I have a data frame and I want to create a column which assigns a letter
 based upon the value in another column.  The data column has velocities
 ranging from 0 to 1000.  So for example, for velocities between 0 and 300
 I'd like to assign the letter A in the new column, for 300-600, B and so
 on and so forth.  How would I do this?

 Thank you very much!

 Mehdi Khan


[[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] Creating a column based on data in another column

2009-08-12 Thread Mehdi Khan
willsclahanstationcut$wills.vs30-
recode(willsclahanstationcut$area.VSCAT,c(B=686,C= 464,BC= 724,
D=301,CD= 372, D= 800, DE= 1000, WATER=0))

where $vs30 is the column I want to create, $area.VSCAT is the column which
contains the labels.


On Wed, Aug 12, 2009 at 8:46 PM, Mehdi Khan mwk...@ucdavis.edu wrote:

 Hey guys, I have the same question, except in reverse: if we had letter
 classifications and wanted to assign numerical values to them (the case I
 stated previously except the other way around) how would we do that?  I am
 trying to use the recode function in the car package but not having any
 luck..

 Thank you!!

 On Fri, Jul 31, 2009 at 12:04 PM, Mehdi Khan mwk...@ucdavis.edu wrote:

 hello all,

 I have a data frame and I want to create a column which assigns a letter
 based upon the value in another column.  The data column has velocities
 ranging from 0 to 1000.  So for example, for velocities between 0 and 300
 I'd like to assign the letter A in the new column, for 300-600, B and so
 on and so forth.  How would I do this?

 Thank you very much!

 Mehdi Khan




[[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] Creating a column based on data in another column

2009-07-31 Thread Jorge Ivan Velez
Dear Medhi,
Take a look at ?cut or ?recode (in the car package).

HTH,

Jorge


On Fri, Jul 31, 2009 at 3:04 PM, Mehdi Khan  wrote:

 hello all,

 I have a data frame and I want to create a column which assigns a letter
 based upon the value in another column.  The data column has velocities
 ranging from 0 to 1000.  So for example, for velocities between 0 and 300
 I'd like to assign the letter A in the new column, for 300-600, B and
 so
 on and so forth.  How would I do this?

 Thank you very much!

 Mehdi Khan

[[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.


[[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] Creating a column based on data in another column

2009-07-31 Thread Dimitris Rizopoulos

have a look at ?cut(); for instance,

x - sample(1000, 20, TRUE)

x
cut(x, c(0, 300, 600, 1000), c(A, B, C))


I hope it helps.

Best,
Dimitris


Mehdi Khan wrote:

hello all,

I have a data frame and I want to create a column which assigns a letter
based upon the value in another column.  The data column has velocities
ranging from 0 to 1000.  So for example, for velocities between 0 and 300
I'd like to assign the letter A in the new column, for 300-600, B and so
on and so forth.  How would I do this?

Thank you very much!

Mehdi Khan

[[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.



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
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] Creating a column based on data in another column

2009-07-31 Thread Henrique Dallazuanna
Try this:

cut(sample(0:1000, 100), breaks = c(0, 300, 600, 900, 1000), labels = c('A',
'B', 'C', 'D'))

On Fri, Jul 31, 2009 at 4:04 PM, Mehdi Khan mwk...@ucdavis.edu wrote:

 hello all,

 I have a data frame and I want to create a column which assigns a letter
 based upon the value in another column.  The data column has velocities
 ranging from 0 to 1000.  So for example, for velocities between 0 and 300
 I'd like to assign the letter A in the new column, for 300-600, B and
 so
 on and so forth.  How would I do this?

 Thank you very much!

 Mehdi Khan

[[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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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] Creating a column based on data in another column

2009-07-31 Thread Mehdi Khan
got it, thank you everyone!

On Fri, Jul 31, 2009 at 12:04 PM, Mehdi Khan mwk...@ucdavis.edu wrote:

 hello all,

 I have a data frame and I want to create a column which assigns a letter
 based upon the value in another column.  The data column has velocities
 ranging from 0 to 1000.  So for example, for velocities between 0 and 300
 I'd like to assign the letter A in the new column, for 300-600, B and so
 on and so forth.  How would I do this?

 Thank you very much!

 Mehdi Khan


[[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.