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.
'교육통계 > Rstudio(english)' 카테고리의 다른 글
Educational statistics Using R - 1. Descriptive statistics 3) inverse item variable (0) | 2022.11.09 |
---|---|
Educational statistics Using R - 1. Descriptive statistics 1) loading data (0) | 2022.11.09 |