Commands for Data Analysis using R
Commands for Data Analysis using R
Summary Statistics with Data frame-(data frame is a type of data structure with two or
more set of data)
NOTE:
There are two ways of writing data frame
1. Writing the datas separately such as
Data1= c(1,2,3,4,5,6,7,8,9,20)
Data2= c(2,4,6,8,10,12,14,16,18,20)
So here there is two set of data and now you want this in table format.
Then the command is
Give any variable name eg:
df= data.frame(Data1=Data1, Data2=Data2) #click enter
df (#click enter)
2. The other way is
df = data.frame("Name" = c("Amiya", "Rosy", "Asish"),"Gender" = c("Male",
"Female", "Male"))
df
(the difference here is instead of writing each data separately you just write directly in
one command)
These are the some of examples
#Contingency table
> table(df)
Output:
Gender
Amiya 0 1
Asish 0 1
Rosy 1 0
# Sample data
gender <- c("Male", "Female", "Male", "Female", "Male", "Female", "Male", "Female",
"Male", "Female")
brand <- c("Apple", "Samsung", "Samsung", "Apple", "Samsung", "Google", "Apple",
"Google", "Samsung", "Other")
#While using strings it is important to notes that it should have “…..” (inside the
brackets only)
# Create a data frame
data_df <- data.frame(Gender = gender, Brand = brand)
File searching
Command IN R Software:
getwd()
enter
"C:/Users/Hp/Documents"
data1=read.csv(file.choose()) enter
data1 Enter
dens = density(ch1_data)
> plot(dens$x, dens$y)
#For channel 2
shapiro_test_result = shapiro.test(ch1_data)
> print(shapiro_test_result)
> qqnorm(ch1_data)
qqline(ch1_data)
> qqnorm(ch2_data)
> qqline(ch2_data)
#Two sample T- # Perform a two-sample t-test with unequal group1 <- c(22, 24,
test with unequal variances (Welch's t-test) 25, 28, 26)
variance (by t_test_result <- t.test(group1, group2, var.equal group2 <- c(30, 32,
default it = FALSE) 31, 35, 33)
assumes equal
variance) # Print the results
print(t_test_result)
(R has equal variance built in function already,
but in this analysis we are going with unequal
variances so while using the above command it
is important to write var.equal=FALSE
Incase you want equal variance then the
command would be var.equal=TRUE
> contingency_table
> summary(anova_result)
> print(tukey_results)
Two Way #Step 1: load the CSV file and organize it into
ANOVA data frames.
GTL=read.csv(file.choose())
> GTL
> summary(anova_result)
TukeyHSD(anova_result)
> weight= c(75, 70, 65, 72, 75, 80, 72, 64)
> student_data
> summary(reg)
summary(correlation)
> summary(reg_model)