0 votes
1 view
in R Programming by (43.2k points)
edited by

I am having a huge amount of data in my data frame- df which has count data generated from two different programs. This is an example of the df:

 Species variable  value

1      "Malassezia;globosa"      100  68126

2      "Aspergillus;nomius"      100  13977

3  "Mitosporidium;daphniae"      100   5953

4 "Penicillium;chrysogenum"      100      1

5                     Other      100    102

6      "Malassezia;globosa"      101 110268

In the whole data frame I am having 311 rows. In that data frame I want to add a column named "Program" and on that column I want to groups rows from 1 to 186 as "HMS" and rows from 187 to 311 as "MiCoP", for example:

 Species variable  value  Program

1      "Malassezia;globosa"      100  68126   HMS

2      "Aspergillus;nomius"      100  13977   HMS

3  "Mitosporidium;daphniae"      100   5953   HMS

4 "Penicillium;chrysogenum"      100      1   HMS

5                     Other      100    102   HMS

6      "Malassezia;globosa"      101 110268   HMS

1 Answer

0 votes
by (92.8k points)

In R programming you can assign the groups based on row number, refer to the following code:

df$Program <- NA #initialise

df$Program[1:186] <- "HMS"

df$Program[187:311] <- "MiCoP"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...