I am sure there is a simple solution to this... I have a column in a
data frame specifying a grouping (1, -1) for my observations, and need
to mutliply each observation in all the other columns of the data frame
by the corresponding value in the given column. I played with apply, and
saw some suggestions for sweep, but did not manage to get it working.
My table contains NAs....
Example of table as data frame
Observation Group Param1 Param2
AA 1 3 4
BB -1 5 6
Expected result:
Observation Group Param1 Param2
AA 1 3 4
BB -1 -5 -6
group<-as.vector(table$Group)
I extracted the first column into a vector, and am looking for a way to
multiply each of the columns... SO far, only manual solutions (uglyyyy)
work: table$Param1<-group*table$Param1
Thanks many times!
Martin
______________________________________________
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.