Friday, October 7, 2016

In R how to correctly read column names that have spaces in their name

In R if you try to correctly read tab separated table in R that has header names written with spaces you will end up with dots put instead of spaces.




> data <-read.delim("AP1_CADSNPs_repeatmasker", header=T)

> data
       X Non.masked Repeat.Filter.masked 
 
 
To correctly read spaces use check.names=FALSE option with read.delim


data <-read.delim("AP1_CADSNPs_repeatmasker", header=T, check.names=FALSE)
 
data$`Repeat Filter masked`
  [1] 1.077 1.113 1.095 1.099 1.083 1.104 1.082 1.103 1.114 1.114 1.113 1.107
 [13] 1.104 1.120 1.111 1.104 1.113 1.112 1.119 1.109 1.098 1.100 1.116 1.118
 [25] 1.080 1.097 1.104 1.100 1.094 1.102 1.111 1.096 1.085 1.106 1.153 1.090
 [37] 1.110 1.098 1.123 1.084 1.110 1.101 1.098 1.112 1.062 1.092 1.112 1.096
 [49] 1.119 1.106 1.095 1.116 1.130 1.094 1.123 1.105 1.085 1.102 1.098 1.106
 [61] 1.127 1.119 1.106 1.116 1.109 1.107 1.126 1.085 1.097 1.111 1.096 1.103
 [73] 1.101 1.107 1.100 1.142 1.129 1.104 1.119 1.139 1.126 1.116 1.131 1.120
 [85] 1.157 1.126 1.151 1.152 1.139 1.135 1.164 1.167 1.177 1.159 1.167 1.159
 [97] 1.171 1.184 1.185 1.055 1.191 1.172 1.159 1.174 1.154 1.176 1.158 1.146
[109] 1.174 1.168 1.150 1.151 1.141 1.126 1.171 1.118 1.111 1.131 1.115 1.113
[121] 1.121 1.133 1.107 1.148 1.087 1.119 1.098 1.099 1.120 1.110 1.106 1.128
[133] 1.119 1.132 1.120 1.112 1.114 1.125 1.104 1.115 1.102 1.132 1.099 1.121
[145] 1.105 1.095 1.120 1.107 1.110 1.095 1.114 1.105 1.102 1.113 1.103 1.097
[157] 1.095 1.101 1.105 1.100 1.099 1.093 1.091 1.107 1.077 1.095 1.084 1.097
[169] 1.113 1.084 1.093 1.087 1.096 1.080 1.093 1.074 1.109 1.105 1.087 1.104
[181] 1.128 1.107 1.102 1.103 1.108 1.099 1.104 1.111 1.105 1.116 1.085 1.093
[193] 1.095 1.082 1.103 1.082 1.083 1.090 1.098


No comments:

Post a Comment