Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Select rows based on conditions of different columns in R

$
0
0

@puja_singh wrote:

I have a csv file "bollywood.csv" bollywood.csv (3.5 KB)

Problem statement :

# # Write a command to find the names of the movies which have the maximum Ocollection, Wcollection, Fwcollecion & Tcollection
#you should get 4 names .Store them in a data frame and show on which category they have max value

Could someone please help on getting desired output .I am new to R ,would be happy on getting help on this .

Desired output :

movie name collection
"Sultan" "Ocollection"
"Dangal" "Tcollection"
"Sultan" "Fwcollection"
"Sultan" "Wcollection"

My code :
library("dplyr")

bollywod = read.csv("bollywood.csv" ,stringsAsFactors = TRUE)
View(bollywod)

OC=max(bollywod$Ocollection)
WC=max(bollywod$Wcollection)
FW=max(bollywod$Fwcollection ,na.rm = TRUE)
TC=max(bollywod$Tcollection)

bollywod_result= bollywod %>% filter(Ocollection == OC |Tcollection ==TC | Wcollection ==WC | Fwcollection==FW) %>% select(Movie)

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles