Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How do I change the structure of a r data table

$
0
0

I've merged a handful of data sets all downloaded from either spss, cvs, or excel files into one large data table. For the most part I can use all the variables I want to run tests but every once in a while the structure of them needs to be changed. As an example here's my data set:

> str(gadd.us)
'data.frame':   467 obs. of  381 variables:
 $ nidaid    : Nmnl. item  chr  "45-D11150341""45-D11180321""45-D11220022""45-D11240432" ...
 $ id        : Nmnl. item  chr  "D11150341""D11180321""D11220022""D11240432" ...
 $ agew1     : Itvl. item  num  17 17 15 18 17 15 15 18 20 18 ...
 $ nagew1    : Itvl. item  num  17.3 17.2 15.7 18.2 17.2 ...
 $ nsex      : Nmnl. item w/ 2 labels for 0,1  num  1 1 0 0 0 0 1 1 1 1 ...

and when I focus on just one variable I get something like this

> str(gadd.us$wasiblckw2)
 Itvl. item + ms.v.  num [1:467] 70 48 40 60 37 46 67 55 45 61 ...
> str(gadd.us$nsex)
 Nmnl. item w/ 2 labels for 0,1  num [1:467] 1 1 0 0 0 0 1 1 1 1 ...

So when I try to create a histogram I get an error...

> hist(gadd.us$wasiblckw2)
Error in hist.default(gadd.us$wasiblckw2) : 
  some 'x' not counted; maybe 'breaks' do not span range of 'x'

If I change this variable using as.numeric() it works just fine. Any idea what's going on here?


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>