Jump to content

Need some help with R

Habby

Well this might be a little too easy to be an actual question, but I'm learning how to use R studio and it's a bit hard to get to know how to use some functions/commands. Basically I have 2 columns,  the first one has the data I want to plot and the other one has labels. How can I sort the data on my dataset to I only use the data from the first column acording to the label I pick?

(edit)

I think I was being to vague, attached an image, basically I want to pick evvery element in the column 1  matching protein in column 2, I am sure I am using "subset()" the wrong way

asd.png

Edited by Habby
adding more information
Link to comment
Share on other sites

Link to post
Share on other sites

a <- seq(1,10,1)
b <- rep(c("protein","somethingelse"),5)
lala <- matrix(nrow=10,ncol=2,data=c(a,b),byrow=FALSE)
lala[which(lala[,2]=="protein"),]
lala[which(lala[,2]=="protein"),][,1]

The only line interesting are the last two.

with which you find the rows that only have protein in column 2 and then using that to retrieve only the first column in the last line for only the data

edit: Using subset

subset(lala, lala[,2] == "protein")
for only data column use:
subset(lala, lala[,2] == "protein")[,1]

change lala to your dataobject name

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, Helibert said:

a <- seq(1,10,1)
b <- rep(c("protein","somethingelse"),5)
lala <- matrix(nrow=10,ncol=2,data=c(a,b),byrow=FALSE)
lala[which(lala[,2]=="protein"),]
lala[which(lala[,2]=="protein"),][,1]

The only line interesting are the last two.

with which you find the rows that only have protein in column 2 and then using that to retrieve only the first column in the last line for only the data

edit: Using subset


subset(lala, lala[,2] == "protein")
for only data column use:
subset(lala, lala[,2] == "protein")[,1]

change lala to your dataobject name

ty a lot for your help man, I'm guessing I can use this for every column and row I want , this was really helpful

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×