# DS-R | OCT 01 - OCT 17 | Nimisha

Discussion in 'Big Data and Analytics' started by Nishant_Singh, Oct 1, 2018.

1. ### Nishant_Singh Well-Known Member Simplilearn Support

Joined:
Aug 1, 2018
Messages:
184
11
Hi Learner,

This thread is assigned for you to discuss the query and concepts related to Data Science with R course.

Happy Learning !!

Regards,
Team Simplilearn

#1
Last edited: Nov 6, 2018
2. ### Nimisha Pandey Active Member Trainer

Joined:
Aug 4, 2017
Messages:
19
8
Prime Numbers :

1. Telling whether a number is prime or Not
2. Get all the prime nos between 2 and 100
3. Get first 20 prime nos.
Fibonacci series :

0, 1, 1, 2, 3, 5, 8, 13, 21,…… till 15th element

Finding Factorial

#2
_41622 and Phanindra_4 like this.
3. ### _42094 Member

Joined:
Sep 28, 2018
Messages:
7
0
Hi Nimisha,

Here is the Assignment solutions. Attached r script as .txt file

Kind Regards
Sreedhar (vensyd)

File size:
1.3 KB
Views:
5
#3
4. ### Meenakshi satpathy Member Alumni

Joined:
May 15, 2017
Messages:
2
0

SOLUTIONS:
#ques1 prime or not

chk_prime <-function(){
num <-as.numeric(readline("Enter number to check number is prime or not "))
t=0
if (num>1){
i=2
while(i<num){
if(num%%i==0){
t=1
break
}
i=i+1
}
}
if(t==0){
print("Prime")
}else{
print("Not Prime")
}
}

chk_prime()
#ques 2

pnt_prime <-function(){
j=3
while(j<100){
t=0
i=2
while(i<j){
if(j%%i==0){
t=1
break
}
i=i+1
}
if(t==0){
print(j)
}
j=j+1
}
}

pnt_prime()

#ques 3 first 20 prime numbers

fst20_prime <-function(){
j=3
cnt=0
while(j<100){
t=0
i=2
while(i<j){
if(j%%i==0){
t=1
break
}
i=i+1
}
if (cnt<20){
if(t==0){
cnt=cnt+1
print(j)
}
}else{
break
}
j=j+1
}
}

fst20_prime()

# fibonacci series

fib <- function(){
a=0
b=1
cnt=2
print(a)
print(b)
while(cnt<16){
c=a
a=b
b=a+c
print(b)
cnt=cnt+1
}
}
fib()

#factorial

fact<-function(){
num <-as.numeric(readline("Enter factorial number you want to find: "))
fact=1
if (num == 0){
print(1)
}else{
while(num>1){
fact=fact*num
num=num-1
}
print(fact)
}
}

fact()

Thanks,
Meenakshi(jinisatpathy)

#4
5. ### Meenakshi satpathy Member Alumni

Joined:
May 15, 2017
Messages:
2
0

SOLUTIONS:
#ques1 prime or not

chk_prime <-function(){
num <-as.numeric(readline("Enter number to check number is prime or not "))
t=0
if (num>1){
i=2
while(i<num){
if(num%%i==0){
t=1
break
}
i=i+1
}
}
if(t==0){
print("Prime")
}else{
print("Not Prime")
}
}

chk_prime()
#ques 2

pnt_prime <-function(){
j=3
while(j<100){
t=0
i=2
while(i<j){
if(j%%i==0){
t=1
break
}
i=i+1
}
if(t==0){
print(j)
}
j=j+1
}
}

pnt_prime()

#ques 3 first 20 prime numbers

fst20_prime <-function(){
j=3
cnt=0
while(j<100){
t=0
i=2
while(i<j){
if(j%%i==0){
t=1
break
}
i=i+1
}
if (cnt<20){
if(t==0){
cnt=cnt+1
print(j)
}
}else{
break
}
j=j+1
}
}

fst20_prime()

# fibonacci series

fib <- function(){
a=0
b=1
cnt=2
print(a)
print(b)
while(cnt<16){
c=a
a=b
b=a+c
print(b)
cnt=cnt+1
}
}
fib()

#factorial

fact<-function(){
num <-as.numeric(readline("Enter factorial number you want to find: "))
fact=1
if (num == 0){
print(1)
}else{
while(num>1){
fact=fact*num
num=num-1
}
print(fact)
}
}

fact()

Thanks,
Meenakshi(jinisatpathy)

#5

Joined:
Sep 28, 2018
Messages:
7
0
#6
7. ### _41622 Member

Joined:
Sep 26, 2018
Messages:
2
0
# get data
class(helt)
# hist of age
hist(helt\$AGE)
summary(as.factor(helt\$AGE))
#convert int to fact
helt\$AGE <- as.factor(helt\$AGE)
class(helt\$AGE)
summary(helt\$AGE)
helt\$AGE<-as.numeric(helt\$AGE)
class(helt\$AGE)
hist(helt\$AGE1)
HI am doing health care project am geeting erro can any suggest how to over come.
ERROR
Error in hist.default(helt\$AGE1) : 'x' must be numeric

#7
8. ### _41622 Member

Joined:
Sep 26, 2018
Messages:
2
0
can anyone give the replay for this quiery

#8
9. ### Kunal Guwalani Well-Known Member Simplilearn Support

Joined:
Jul 17, 2018
Messages:
141
9
Hi Learner,

I would like to suggest you that there is no need to convert helt\$AGE as numeric you can refer the folloing code.
age=table(HospCost\$AGE)
View(HospCost)
Freq=table(HospCost\$AGE)
barplot(Freq)
class(Freq)
View(HospCost)
TotalChrgByAge=tapply(HospCost\$TOTCHG,HospCost\$AGE,max)
TotalChrgByAge

#9
10. ### Bo Yuan Member

Joined:
Sep 3, 2018
Messages:
13
0
I am not able to take the data science with R simulation test in LMS. It is keep loading and wont start. This issue has been there for a long time for me that trouble me to unlock the certificate.

I have tried IE, Chrome, Firefox.... None of them can load the page successfully. The page looks like this.

#10
11. ### Priyanka_Mehta Well-Known Member Simplilearn Support

Joined:
May 25, 2017
Messages:
857
55
Hi, Apologies for the inconvenience. We have already forwarded it to the concerned team and will get it rectified as early as possible.

#11

Joined:
May 25, 2017
Messages:
857