-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_attributes_pnet.R
More file actions
89 lines (59 loc) · 4.18 KB
/
node_attributes_pnet.R
File metadata and controls
89 lines (59 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#####################################################
# #
# R script to read in and clean #
# node attribute data #
# #
#####################################################
library(plyr)
library(dplyr)
library(readxl)
library(foreign)
# set working directory
# setwd("~/ownCloud/Innovation Network Analysis/Case studies/HF") # MacBook
setwd("d:/Andrew/ownCloud/Innovation Network Analysis/Case studies/HF") # Home PC
# read node attribute data
nodes <- read_excel("surveydata.xlsx", sheet = 1)
write.csv(nodes, file = "temp.csv",row.names = FALSE)
nodes <- read.csv("temp.csv")
# remove strings from numeric data
nodes$Age <- as.numeric(gsub("([0-9]*).*","\\1",nodes$Age)) # extract years only
nodes$Experience <- as.numeric(gsub("([0-9]*).*","\\1",nodes$Experience)) # extract years only
nodes$Tenure <- as.numeric(gsub("([0-9]*).*","\\1",nodes$Tenure)) # extract years only
# fix column names
colnames(nodes)[10] <- "Occupation"
# totalize scale items
## first we need to reverse scores where necessary
nodes$Openness2 <- 10 - nodes$Openness2 # openness scale item 2
nodes$Conscientiousness1 <- 10 - nodes$Conscientiousness1 # conscientious scale item 1
nodes$Agreeableness2 <- 10 - nodes$Agreeableness2 # agreeableness scale item 2
## next we need to aggregate 12 scales from 32 items
## TIPI personality
nodes$Openness <- round(rowMeans(subset(nodes, select = c(Openness1,Openness2)), na.rm = TRUE)/10, digits = 2) # openness
nodes$Conscietiousness <- round(rowMeans(subset(nodes, select = c(Conscientiousness1,Conscietiousness2)), na.rm = TRUE)/10, digits = 2) # consceintiousness
nodes$Agreeableness <- round(rowMeans(subset(nodes, select = c(Agreeableness1,Agreeableness2)), na.rm = TRUE)/10, digits = 2) # agreeableness
##
nodes$Competence <- round(rowMeans(subset(nodes, select = c(Competence1,Competence2,Competence3)), na.rm = TRUE)/10, digits = 2) # job competence
##
nodes$SelfDetermination <- round(rowMeans(subset(nodes, select = c(SelfDetermination1,SelfDetermination2,SelfDetermination3)), na.rm = TRUE)/10, digits = 2) # self determination
## creative self-efficacy
nodes$Creativity <- round(rowMeans(subset(nodes, select = c(Creativity1,Creativity2,Creativity3,Creativity4)), na.rm = TRUE)/10, digits = 2) # creativie self-efficacy
## work motivation
nodes$Amotivation <- round(rowMeans(subset(nodes, select = c(Amotivation1,Amotivation2,Amotivation3)), na.rm = TRUE)/10, digits = 2) # amotivation
nodes$ExtrinsicRegulationSocial <- round(rowMeans(subset(nodes, select = c(ExtrinsicRegulationSocial1,ExtrinsicRegulationSocial2,ExtrinsicRegulationSocial3)), na.rm = TRUE)/10, digits = 2) # extrinsic regulation - social
nodes$ExtrinsicRegulationMaterial <- round(rowMeans(subset(nodes, select = c(ExtrinsicRegulationMaterial1,ExtrinsicRegulationMaterial2,ExtrinsicRegulationMaterial3)), na.rm = TRUE)/10, digits = 2) # extrinsic regulation material
nodes$IntrojectedRegulation <- round(rowMeans(subset(nodes, select = c(IntrojectedRegulation1,IntrojectedRegulation2,IntrojectedRegulation3,IntrojectedRegulation4)), na.rm = TRUE)/10, digits = 2) # introjected regulation
nodes$IdentifiedRegulation <- round(rowMeans(subset(nodes, select = c(IdentifiedRegulation1,IdentifiedRegulation2,IdentifiedRegulation3)), na.rm = TRUE)/10, digits = 2) # identified regulation
nodes$IntrinsicMotivation <- round(rowMeans(subset(nodes, select = c(IntrinsicMotivation1,IntrinsicMotivation2,IntrinsicMotivation3)), na.rm = TRUE)/10, digits = 2) # intrinsic motivation
# remove unwanted columns now we have totalized scores
column_names <- as.data.frame(names(nodes)) # get numbered list of columns
column_names # lists column names with corresponding column numbers
node_summary <- subset(nodes, select=-c(2:4,13:51)) # drop unwanted columns using column numbers
# write out cleaned-up node data
## binary actor attribute file
gender <- subset(nodes, select = -c(2:4,6:63))
file <- "gender.txt"
writeLines("id,gender", file)
write.table(gender, file = file,
sep = "\t", na = "", quote = FALSE,
col.names = FALSE, row.names = FALSE,
append = TRUE)