교육통계/Rstudio(english)

Educational statistics Using R - 1. Descriptive statistics 2) variables

개노답이글스 2022. 11. 9. 19:14

It's good to see you again

 

In this chpater, I tried to make a variable

 

Firtst, load a dataset(whatever you use)

 

 

check my dataset..

 

2590 objects, and 378 variables in data

 

 

now, make a variable by 'apply' function

 

how to use it?

 

apply(dataset[,column number:column number],1,mean)

 

dataset : set your data

[,column number:column number] : becareful 'comma' place and select column number for variable

 

,1 : specify by column

 

mean : cacluate average

 

and  also use '$'

 

this is formula for variable

 

dataset$new_variable_name = apply(dataset[,column number:column number],1,mean]

 

Let's see

 

in my data, use 16 questions for variable 

 

their locations are column number 52 to 67

 

so, 

 

 

then chcek data... View(dataset) is useful

 

the new variable is added at the end of column 

 

NA means it is NULL 

 

the new variable is made with average

 

to be continued..

 

Thank you.