This question already has answers here:
How to reshape data from long to wide format
(14 answers)
Pivot_wider function (tidyr r package) from multiple variables
(2 answers)
Closed 8 months ago.
Hey guys I am trying to build a pivot table in R which I just started using. I know this topic has been discussed a few times here but I can't find an example that would help me out. I have data table which looks like following
What I am trying to do is build a triangle with Years as columns. Country & City as rows. So it looks like this
I have tried using group_by but can't figure it out. Would really appreciate any advice I can get!
Thanks in advance
This question already has answers here:
How to reshape data from long to wide format
(14 answers)
Closed 2 years ago.
I have a dataset in below format
I am trying to get an output in below format using R. The product names for each sales order must be split in columns. There are multiple SalesOrderNumbers and for each of the the numbers of products could be n.
This is a "convert data frame from long to wide format" question. There are many resources on that. The post "How to reshape data from long to wide format" will give you directions on how to do it. Here is another source https://www.datacamp.com/community/tutorials/long-wide-data-R.
Please try that, first. If you have any trouble with it, we will be glad to help you.
This question already has answers here:
Factors in R: more than an annoyance?
(8 answers)
Closed 5 years ago.
I am new to R language and am not able to understand the need to use/have Factors in R and its killing me. I read a lot but still have not found the satisfactory answer. Any help would be much appreciated. Thank you.
It is a way to associate numbers to different values of a categorical variable.
Let's say you have a vector of genders, and you wish to introduce it to some model (lm for example). Then you need to code the values (0/1 perhaps). Here you will use factor on the vector of genders
This question already has answers here:
How to find common elements from multiple vectors?
(3 answers)
Closed 5 years ago.
I have two RNAseq read-outs for two groups and would like to compare them. These data appear as a gene and a value. I would like to determine which genes are shared between the two datasets but they are very large and doing this manually will take a long time. Thanks!
Use
intersect(genes1, genes2)
and look up the help page for other related and useful functions.
This question already has answers here:
placing mean,total and max together in a table in r
(3 answers)
Closed 9 years ago.
I've got some code below which I'd like to be able to combine into one big table. Is this possible?
cbind(sum(michelson[michelson$Expt==1,]$Speed),
mean(michelson[michelson$Expt==1,]$Speed),
max(michelson[michelson$Expt==1,]$Speed))
cbind(sum(michelson[michelson$Expt==2,]$Speed),
mean(michelson[michelson$Expt==2,]$Speed),
max(michelson[michelson$Expt==2,]$Speed))
cbind(sum(michelson[michelson$Expt==3,]$Speed),
mean(michelson[michelson$Expt==3,]$Speed),
max(michelson[michelson$Expt==3,]$Speed))
cbind(sum(michelson[michelson$Expt==4,]$Speed),
mean(michelson[michelson$Expt==4,]$Speed),
max(michelson[michelson$Expt==4,]$Speed))
cbind(sum(michelson[michelson$Expt==5,]$Speed),
mean(michelson[michelson$Expt==5,]$Speed),
max(michelson[michelson$Expt==5,]$Speed))
I'd appreciate some help please from some experts! Thanks
Explaining what you are trying to achieve will help someone answer rather than pasting only the code ... From what I can understand from your code, ddply seems to be a right choice here as pointed out by #Henrik