[R] Data.frame Question

2010-03-11 Thread GULATI, BRIJESH (Global Markets FFO NY)


   Hi: 
   I want to add a constant to an existing col of the
 data.frame. I have the following dataset:
 
 
   structure(list(x = c(1, 1, 1, 1, 1), y = c(1, 1, 1, 1, 1)),
 .Names = c(x, 
   y), row.names = c(NA, 5L), class = data.frame)
 
 
   I want to add a constant to col 1 and col 2 to get the following
 data.frame 
 
   structure(list(x = c(2, 2, 2, 2, 2), y = c(3, 3, 3, 3, 3)),
 .Names = c(x, 
   y), row.names = c(NA, 5L), class = data.frame)
 
 
   Thanks, 
   Brijesh

--
This message w/attachments (message) may be privileged, ...{{dropped:30}}

__
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] Data.frame Question

2010-03-11 Thread Henrique Dallazuanna
Try this:

sweep(DF, 2, 1:2,  '+')

On Thu, Mar 11, 2010 at 9:20 AM, GULATI, BRIJESH (Global Markets FFO
NY) brijesh.gul...@baml.com wrote:


       Hi:
               I want to add a constant to an existing col of the
 data.frame. I have the following dataset:


       structure(list(x = c(1, 1, 1, 1, 1), y = c(1, 1, 1, 1, 1)),
 .Names = c(x,
       y), row.names = c(NA, 5L), class = data.frame)


       I want to add a constant to col 1 and col 2 to get the following
 data.frame

       structure(list(x = c(2, 2, 2, 2, 2), y = c(3, 3, 3, 3, 3)),
 .Names = c(x,
       y), row.names = c(NA, 5L), class = data.frame)


       Thanks,
       Brijesh

 --
 This message w/attachments (message) may be privileged, ...{{dropped:30}}

 __
 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

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


[R] Data.frame Question (add constant to a row)

2010-03-10 Thread GULATI, BRIJESH (Global Markets FFO NY)


 Hi: 
   I want to add a constant to an existing col of the data.frame. I
 have the following dataset:
 
 
 structure(list(x = c(1, 1, 1, 1, 1), y = c(1, 1, 1, 1, 1)), .Names =
 c(x, 
 y), row.names = c(NA, 5L), class = data.frame)
 
 
 I want to add a constant to col 1 and col 2 to get the following
 data.frame 
 
 structure(list(x = c(2, 2, 2, 2, 2), y = c(3, 3, 3, 3, 3)), .Names =
 c(x, 
 y), row.names = c(NA, 5L), class = data.frame)
 
 
 Thanks, 
 Brijesh

--
This message w/attachments (message) may be privileged, ...{{dropped:30}}

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


[R] data.frame question

2010-03-07 Thread joseph
hello

can you show me how to create a data.frame from two factors x and y. column 1 
should be equal to x and column 2 is 1 if it is common to y and 0 if it is not.

x=factor(c(A,B,C,D,E,F,G))
y=factor(c(B,C,G))

the output should look like this:
A0
B1
C1
D0
E0
F0
G1

Thanks 
Joseph Dhahbi


  
[[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] data.frame question

2010-03-07 Thread baptiste auguie
Hi,

try this,

data.frame(x,as.numeric(x %in% y))

HTH,

baptiste

On 7 March 2010 21:06, joseph jdsan...@yahoo.com wrote:
 hello

 can you show me how to create a data.frame from two factors x and y. column 1 
 should be equal to x and column 2 is 1 if it is common to y and 0 if it is 
 not.

 x=factor(c(A,B,C,D,E,F,G))
 y=factor(c(B,C,G))

 the output should look like this:
 A    0
 B    1
 C    1
 D    0
 E    0
 F    0
 G    1

 Thanks
 Joseph Dhahbi



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




-- 

__
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] data.frame question

2010-03-07 Thread Stephan Kolassa

Hi,

data.frame(x=x,y=as.numeric(x%in%y))

HTH,
Stephan


joseph schrieb:

hello

can you show me how to create a data.frame from two factors x and y. column 1 
should be equal to x and column 2 is 1 if it is common to y and 0 if it is not.

x=factor(c(A,B,C,D,E,F,G))
y=factor(c(B,C,G))

the output should look like this:
A0
B1
C1
D0
E0
F0
G1

Thanks 
Joseph Dhahbi



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



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