Data Frame

 Data Frame

Code

id <- c(101,102,103)
name <- c('John','Jonny','Jack')
marks <- c(78.25,59.45,63.85)
students <- data.frame(id,name,marks)
students
studentslist <- list(id,name,marks)
studentslist

students[1,]
students[1:2,]
students[,2]
students[1]  #Just refers to colomn
students$id
students$id[2]

students[[3]][2] = 89.65  # First Index is always colomn
students

students[3,1] = 103.5
students[3,3] = 'No Marks'
students[3,2] = 'Bob'      #Something about Factor
students

stud = students[-2,-3]
stud

report=subset(students,marks>60)
report
report=subset(students,marks>60 & id==101)
report
report=subset(students,marks>60,select=c(name))
report
report=subset(students,marks>60,select=c(name,marks))
report
report=subset(students,marks>60,select=name:marks)
report
report=subset(students,marks>60,select=-id)
report
report=subset(students,select=c(name,marks))
report

id = c(101,102,103)
name = c('John','Jonny','Jack')
marks = c(78.25,59.45,63.85)
students = data.frame(id,name,marks)
print(students)

students = rbind(students,data.frame(id=104,name='Bob',marks=45.85))
print(students)

students = cbind(students,age=c(10,20,30,40)) #Should have same # of values(rows)
print(students)

id = c(101,102,103)
name = c('John','Jonny','Jack')
marks = c(78.25,59.45,63.85)
students = data.frame(id,name,marks)
print(students)

stud = edit(students)
print(stud)

x <- c(10,4,NA,7,15)
x
is.na(x)
is.nan(x)

x <- c(10,4,NA,7,NaN)
x
is.na(x)
is.nan(x)

x <- c(10,4,NA,7,NA)
x
y <- is.na(x)
y
x[!y]

id <- c(101,102,103,104,105)
temperature <- c(25.8,34.2,NA,27.4,20.5)
wind <- c(78,59,63,40,68)
humidity <- c(25,45,85,NA,61)
weather <- data.frame(id,temperature,wind,humidity)
weather

weatherNA <- complete.cases(weather)
weatherNA

weather[weatherNA,]

Comments

Popular posts from this blog

Probability: Binomial Distribution

Probability: Normal Distribution

Hypothesis testing