data frame slicing
Title
Question
in the assignment
my code is
subdata <- subset(captaincy,played>20&&lost<14,select =c("names","played","won","lost"))
print(subdata)
result is
names played won lost
1 Mahi 45 22 12
2 Sourav 49 21 13
3 Azhar 47 14 14
4 Sunny 47 9 8
5 Pataudi 40 9 19
6 Dravid 25 8 6
in lost column we have 19 but it should be less than 14 know.
R Indexing-and-Slicing-Data-Frames 01-02 min 0-10 sec
Answers:
Please use & in place of && while combining played>20 and lost<14. So, the code should be written as given below:
subdata <- subset(captaincy, played>20 & lost<14, select =c("names","played","won","lost"))
Please use & instead of &&
<- subset(captaincy,played>20 & lost<14,selet=c("names","played","won"))
> print(subdata)
names Y played won lost victory
1 Mahi 2012 45 22 12 0.4888889
2 Sourav 2004 49 21 13 0.4285714
4 Sunny 1980 47 9 8 0.1914894
6 Dravid 2008 25 8 6 0.3200000
Login to add comment