1

I'm trying to create a variable out of a single point in 5 different data tables.

ie. I have data for mental disorders for each year in seperate CSV files. How do I track just one variable (eg Autism) in each file and put it into one variable?

Here is what I have so far:

d2000 <- read.table("C:/AL00.csv")
d2001 <- read.table("C:/AL01.csv")
d2002 <- read.table("C:/AL02.csv")
d2003 <- read.table("C:/AL03.csv")

rownames(d2000) <- d2000[,3]
rownames(d2001) <- d2001[,3]
rownames(d2002) <- d2002[,3]
rownames(d2003) <- d2003[,3]

ASD = c(d2000["Autism","Total"],d2001["Autism","Total"],d2002["Autism","Total"])

This isn't working. I tried typing in just one of the data points:

>d2000["Autism","Total"]
[1] 2,763
Levels: 1,075 1,480 2,763

It outputs the correct number, but what are these "Levels"? Are they my problem, if so, how would I fix?

4

1 回答 1

0

我会做这样的事情:

ll <- lapply(list.files(pattern="AL[0-9]+.*csv",full.names=TRUE),
             function(x) read.table(x, stringsAsFactors=FALSE))
res <- do.call(rbind,ll)[,'Autism']

这将为您提供向量中的自闭症列。然后要将其转换为数字,您可以执行一些正则表达式:

as.numeric(gsub(',','',res))
于 2013-06-20T14:49:53.110 回答