R beginner here: After searching for what must be a simple answer for over a day, decided to post my first ever question on here:
I would like to multiply (or divide) numeric columns in a dataframe with a numeric vector. The dataframe contains not just numbers but also strings. In my search I've learned about t(t(mydf) * myvec))
, sweep()
, scale()
, *apply()
and replacement operations, but I'm having trouble figuring out a clever function to allow me to specify which columns are multiplied without subsetting the dataframe.
How can multiply/divide each row in the last two columns of test.dat with myvec and get back a dataframe that contains the result along with the unaltered columns> (Yes for the numerics I could just add a '1' to myvec). But how do I deal with the names? Thank you in advance!!
Proper Example:
mydf <-as.data.frame(rbind(c("chrX", 5624624, 5631869, "Nudt11", 2, "+", 1, 7245, 1.332, 9651.3), c("chrX", 5977262, 6210835, "Shroom4", 9, "+", 1, 233573, 1.357, 316914)))
colnames(mydf)<-c("chr", "start", "end", "name", "score", "strand", "score2", "width", "value", "value2")
myvec<-c(10, 0.0001)
mydf
is a matrix. when yourbind
, if there is not at least onedata.frame
as input, the output will be "bind" (bound) as a matrix. Usedata.frame(.)
to create your input instead. – Arun