I am new to programming in R and Python, however have some basics. I have a technical question about computation. I would like to know if there are any functions for performing subtraction of all features(rows) to a particular value (row) from the same data list. I would like to obtain the output_value1 as shown below and post this, multiply by (-1) to obtain the output_value2.
Please let me know if you need more details.
I have tried performing the same operation in the MS Excel, this is very tedious and time consuming.
I have many large datasets with several hundred rows and columns which becomes more complex to manually perform the same in MS Excel. Hence, I would prefer to write a code and obtain the desired outputs.
|Feature| |Value| |Output_value1| |Output_value2|
|Gene_1| |14.25633934| |0.80100922| |-0.80100922|
|Gene_2| |16.88394578| |3.42861566| |-3.42861566|
|Gene_3| |16.01| |2.55466988| |-2.55466988|
|Gene_4| |13.82329514| |0.36796502| |-0.36796502|
|Gene_5| |12.96382949| |-0.49150063| |0.49150063|
|Normalizer| |13.45533012| |0| |0|
Thank you Tokhir. This was helpful and worked fine.
But if I have hundreds of values/sample columns in the data file, for instance as given below:
How could this be modified? For this purpose, can I change the function to df1$Output_value1 <- df1$Value[1:n] - df1[ df1$Feature == "Normalizer", "Value"]
where n is the number of values/samples.
Provide representative example data.
example data
example data attached in the link.
Where,
O.Value1 = Value1 of [gene_1, gene_2, gene_3, gene_4, gene_5] - [Value1 of Normalizer]
Negative.O.Value1 = (-1) *O.Value1
till
O.Value13
Negative.O.Value13
We can use sweep:
Thank you. Just one more question,
In case, I would like to print only specific columns as shown in the attached example data file from the O.Value1 to O.Value13 columns without the populating other columns, how can I deal with it? And later, print separately (-1) *O.Values as a different list. Does the below code looks fine?
To obtain output values
O.Value <- cbind( sweep(df1[, -1], 2, unlist(df1[ df1$Feature == "Normalizer", -1 ]), "-") )
To obtain Negative output values
Negative.O.Value <- cbind( -sweep(df1[, -1], 2, unlist(df1[ df1$Feature == "Normalizer", -1 ]), "-") )