Use data frame row data to solve systems of linear equations with solve function in R
0
0
Entering edit mode
2.9 years ago
boomshackle ▴ 30

Hello,

I am trying to solve a system of equations to do some error correction for mass spec data. The current situation is that I am solving a system of equations based on 12 unknown values. I have figured out how to use the solve(A, b) function in R to calculate one set of data but I have a data frame with thousands of entries. What I would like to do is be able to pull a row out of the table and use it as the solution vector for the solve function. A function to solve row by row with the solve function. Each row is a set of solution values for a solution vector. I have a coefficient vector set up that does not change and is static. This is what I have so far...

A <- read.csv("CE.csv", header = FALSE) #This is the vector used to store the coefficient values for the solve function
b <- read.csv("sVar.csv", header = TRUE) #These are the solution values for the solve function in a data frame from a csv

b1 <- array(c(13636.62207,12347.89844,14152.16211,17058.18555,12346.5498,14762.48438,13288.41699,14217.6377,17344.58008,15957.02148,12569.34473,13400.34277), c(12,1))

#b1 serves as how I am currently pulling the values to calculate solve. Its an example of an entry pull from one row of b

solve(A, b1)


[,1] V1 1496.373 V2 12808.015 V3 12899.654 V4 17130.850 V5 13366.542 V6 16365.098 V7 14541.283 V8 14313.790 V9 17844.002 V10 16568.546 V11 13071.996 V12 13969.200

So in all I am looking to pull a row of data from a data frame, enter it into a solution vector then use it to calculate a set of 12 unknown variables for each entry and enter them into either a new data frame or as a new column of b.

R Mass Spec • 752 views
0
Entering edit mode

Hello boomshackle!

We believe that this post does not fit the main topic of this site.

Doesn't look like bioinformatics, please correct me if I'm wrong.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

0
Entering edit mode

I am working with proteomics mass spec data set for determination of up and down regulations of proteins in a set of 12 samples. I do not understand how that is not bioinformatics?

0
Entering edit mode

Hey boomshackle, I think that we just feared that your post would go unanswered, so we felt it better to initiate a response / some dialogue. On face value, it appears that you just need some assistance with creating a re-usable function in R that can be applied for any row from your data-frame, but the simplicity of that process (writing a function) seems to contrast with the general 'complex' nature of what you want to do, i.e., solve functions, solution vectors, etc. Just an atypical post from that with which most of us are familiar

0
Entering edit mode

I did not see any content related to bioinformatics - what I saw was a pure R question. If the data context/information on the problem had been added, this confusion could have been averted. Please state your premise more clearly in future posts.