Are there any functions to subtract all features(rows) to a particular value(row) in the same data file?
1
0
Entering edit mode
@mohammedtoufiq91-17679
Last seen 8 weeks ago
Qatar

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 outputvalue1 as shown below and post this, multiply by (-1) to obtain the outputvalue2.

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|

R python normalization matrix • 378 views
ADD COMMENT
2
Entering edit mode
shahryary ▴ 30
@shahryary-20561
Last seen 2.2 years ago

You can do it easily in R.

df<-fread("yourfile")
df$Output_value2 <- ( df$Output_value1 * -1)

Note: for large data-set try to use "data.table" package to read/write.

ADD COMMENT
0
Entering edit mode

Thank you. But if I have hundreds of values/sample columns arranged in the data file , for instance as given below:

 |Feature| |Value1| |Value2| |Value3| |Value4| |Value5| |Value...n|

How could this be done to obtain the output in the single table? df1$Outputvalue1, df1$Outputvalue2, df1$Outputvalue3, df1$Outputvalue4, ........df1$Output_valueN

Here, df1$Output_value = difference between (Feature [1 to 5] - Feature [Normalizer])

Basically, Initially I would like to obtain the df1$Outputvalue from 1,.....N table and then multiply by (-1) in the next step i.e df$Outputvalue2.

ADD REPLY
0
Entering edit mode

Well, as I understand you have many columns that you want to multiply in -1 and write result as new column.

So, here you can do it for every column and add the result as new column.

i <- 1
for (i in seq_len(length(df[,2:6]))){
    cur.colname <- colnames(df)[i]     # name of current column 
    df$tmp<-( df[,i:i] * -1 )          # multiply in -1 
    # adding new value as new column
    colnames(df)[names(df)=="tmp"] <- paste0("Value_",cur.colname)       
}

df[,2:6] is index of your columns.

ADD REPLY
0
Entering edit mode

Thank you shahryary.

ADD REPLY

Login before adding your answer.

Traffic: 404 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6