[R] Setting Values of Elements in a Dataframe

2010-11-29 Thread Lorenzo Isella

Dear All,
I am experiencing some problems in resetting the values of some selected 
elements in a dataframe.


Consider


d-seq(-1,1,length=16)
dim(d)-c(4,4)
d-as.data.frame(d)

sel_pos-which(d0, arr.ind=TRUE)

d[sel_pos]- -9

which returns the error

Error in `[-.data.frame`(`*tmp*`, sel_pos, value = -9) :
  only logical matrix subscripts are allowed in replacement

which is obscure to me. I am correctly selecting the positive elements 
in a data.frame and I'd like to reset them to another numerical value.

What I am misunderstanding?
Many thanks

Lorenzo

__
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] Setting Values of Elements in a Dataframe

2010-11-29 Thread Henrique Dallazuanna
Try this:

 d[d  0] - -9

On Mon, Nov 29, 2010 at 1:56 PM, Lorenzo Isella lorenzo.ise...@gmail.comwrote:

 Dear All,
 I am experiencing some problems in resetting the values of some selected
 elements in a dataframe.

 Consider


 d-seq(-1,1,length=16)
 dim(d)-c(4,4)
 d-as.data.frame(d)

 sel_pos-which(d0, arr.ind=TRUE)

 d[sel_pos]- -9

 which returns the error

 Error in `[-.data.frame`(`*tmp*`, sel_pos, value = -9) :
  only logical matrix subscripts are allowed in replacement

 which is obscure to me. I am correctly selecting the positive elements in a
 data.frame and I'd like to reset them to another numerical value.
 What I am misunderstanding?
 Many thanks

 Lorenzo

 __
 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] Setting Values of Elements in a Dataframe

2010-11-29 Thread Ivan Calandra

Hi,

Not sure why it doesn't work (I would say it's because of the structure 
of sel_pos, but I don't know how to deal with it).


But just do:
d[d0] - -9
It does work

HTH,
Ivan

Le 11/29/2010 16:56, Lorenzo Isella a écrit :

Dear All,
I am experiencing some problems in resetting the values of some 
selected elements in a dataframe.


Consider


d-seq(-1,1,length=16)
dim(d)-c(4,4)
d-as.data.frame(d)

sel_pos-which(d0, arr.ind=TRUE)

d[sel_pos]- -9

which returns the error

Error in `[-.data.frame`(`*tmp*`, sel_pos, value = -9) :
  only logical matrix subscripts are allowed in replacement

which is obscure to me. I am correctly selecting the positive elements 
in a data.frame and I'd like to reset them to another numerical value.

What I am misunderstanding?
Many thanks

Lorenzo

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



--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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