简体   繁体   中英

how to loop row wise in a csv file in R

I have a csv file like this:

 Project Name jan feb mar apr may jun july aug sep oct nov dec
 1        proj1  23  56  76  43  22  99   76 878  54  99  43 534
2        proj2  65  68  33  76  34  66    3  78  44  78  44 778
3        proj3  72  35  21  35  38  92   26  58 745  98  67  43

I need a for loop which will loop through this data and give me row wise data so that I will be able to retrieve the count of each month for each project.

Try using rowSums :

drops <- c("Project", "Name")
df$total <- rowSums(df[, !(names(df) %in% drops)])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM