How to Split one row into two - r

I want to create multiple columns based on subjects and Marks. data in column Name and Age will remain same for different subjects as shown
My first table is input data and the second one is desired output.

Related

Merging two data-frame with different observation which are including same column in r

I have two data-frames with different observations but including same column let say "id". The values of column "id" are duplicated in bigger data-frame. Also, in the small data-frame there is a column called "names" which is not existed in a bigger df. I want to add new column called "name" into my bigger df like this:

how to extract the lines that have equal values in a table between the different columns

I have a data table, where I would like to extract the rows that are equal in the different columns
what are the different functions to get there ?

How to combine rows based off of duplicate values?

Basically what we have is several columns as follows:
Household ID, restaurantspend, groceryspend, foodtruckspend
We have duplicate household ids because each spend is in its own individual column so an example of our data looks like this:
data example
We want to have the Household ID only have 1 row per id and combine the numerical values of the other column.
aggdata = aggregate(mydata, by=list(mydata$HouseHoldID),Fun=sum)
I have created the above table and saved it as "Mydata". Run the above code. View the output "aggdata", you can see an extra column "Group.1" that's the group based on "HouseHoldID". You can ignore the second column "HouseHoldId" as the same information will be available in the column "Group.1".

How to sort the first 20 rows in first column in alphabetical order in a data frame

I'm new to R coding and i'm doing exercises and I got stuck. In my data frame, the first row are patients e.g patient 1, patient 2 etc and the first column are gene names eg gene abc123,gene def456. What I want to know is how to sort the first 20 rows in column 1 in alphabetical order. Thanks
EDIT
I have put up a screenshot of the file in excel and i am trying to extract the ones in the red box in alphabetical order. I am unsure what to call column 1 in the console as it doesn't have a heading. In the file provided, each row represents expression values for a single gene, and each column
represents expression values for a single sample (patient).
The first column of each row is the gene identifier: (gene-symbol|entrez ID)
e.g. "A2M|2" (A2M is the gene-symbol and 2 is the entrez database identifier for alpha 2 macroglobulin)
Each sample identifier is formatted as: TCGA-ID_Tissue
where the Tissue is either "TissueA" or "TissueB" e.g. "TCGA-AA-3548_TissueA"
The question is "Sort the gene names alpahabetically (A-Z) and print out the first 20 gene names"
screenshot of the table

Problems creating table from data in long format

I'll describe my data:
First column are corine_values, going from 1 to 50.
Second column are bird_names, there are 70 different bird_names, each corine_value has several bird_names.
Third column contains the sex of the bird_name.
Fourth column contains a V1-value (measurement) that belongs to the category described by the first three columns.
I want to create a table where the the row names are the bird_names. First all the females in alphabetical order, followed by the males in alphabetical order. The column names should be the corine_values, from small to big. The data in the table should be the corresponding V1-values.
I've been trying some things, but to be honest I'm just starting with R and I don't really have a clue how to do it. I can sort the data, but not on multiple levels (like alphabetical and sex combined). I'm exporting everything to Excel now and doing it manually, which is very time-consuming.

Resources