You are on page 1of 3

R Practice 2 - Summarizing Data

Arshya Pooladi-Darvish

2022-07-07

PRE TASK

act<-read.csv("/Users/arshyapooladi-darvish/Downloads/actdata2.csv")
str(act)

## ’data.frame’: 871 obs. of 9 variables:


## $ encounter: int 4 3 4 3 1 1 1 2 3 1 ...
## $ share : int 2 2 2 1 2 2 2 2 1 1 ...
## $ sharefake: int 2 1 2 2 2 2 2 2 1 1 ...
## $ public : int 4 1 4 2 1 2 1 4 1 1 ...
## $ recognize: int 2 1 2 1 1 1 1 4 1 2 ...
## $ employ : int 3 1 1 3 1 1 3 3 2 1 ...
## $ parent : int 2 2 1 2 2 1 2 2 1 1 ...
## $ sex : int 2 1 2 1 1 1 2 1 2 1 ...
## $ age : int 75 29 34 75 60 50 72 55 25 48 ...

TASK 1

act<-read.csv("/Users/arshyapooladi-darvish/Downloads/actdata2.csv")
sex_cat<-act$sex
v1=871
v2=1
v3=0
v4=0
while(v2<=v1){

if(sex_cat[v2] ==1){
sex_cat[v2] <- "male"
v3=v3 + 1
}
else{
sex_cat[v2] <- "female"
v4=v4 + 1
}
v2 = v2 +1
}
act$sex<-sex_cat
str(act)

## ’data.frame’: 871 obs. of 9 variables:


## $ encounter: int 4 3 4 3 1 1 1 2 3 1 ...

1
## $ share : int 2 2 2 1 2 2 2 2 1 1 ...
## $ sharefake: int 2 1 2 2 2 2 2 2 1 1 ...
## $ public : int 4 1 4 2 1 2 1 4 1 1 ...
## $ recognize: int 2 1 2 1 1 1 1 4 1 2 ...
## $ employ : int 3 1 1 3 1 1 3 3 2 1 ...
## $ parent : int 2 2 1 2 2 1 2 2 1 1 ...
## $ sex : chr "female" "male" "female" "male" ...
## $ age : int 75 29 34 75 60 50 72 55 25 48 ...

vals <- c(v3,v4)


dt = data.frame(
male=v3,
female=v4)

dt

## male female
## 1 422 449

print("TASK 2")

## [1] "TASK 2"

boxplot(age~employ,data=act)
80
60
age

40
20

1 2 3

employ

2
print("TASK 3")

## [1] "TASK 3"

fake<-data.frame(subset(act,act$sharefake==1))
d<-nrow(fake)

fakec<-data.frame(subset(fake,(fake$recognize==1)))
n<-nrow(fakec)
n/d

## [1] 0.368

#**n:** numerator is those who share a fake story despite being confident in ability
#**d:** denominator is those who shared a fake story

print("TASK 4")

## [1] "TASK 4"

barplot(height = nrow(act))
800
600
400
200
0

You might also like