Hi, I am trying to convert the SPSS data that I imported using the package foreign into a matrix form in R. I tried using write.table() and cbind() but the output still looks bizzarre. I have about 104 columns and 21143 rows. Is the size of the the data causing a problem? Here was my approach mydata<-("file location",max=0) mydata cbind(mydata) #doesnt work well write.table(mydata) #distorted output I also tried data.frame(mydata) #but this gives me only 4 columns (though properly arranged) Is there a better way to resolve this problem? Thanks [[alternative HTML version deleted]]
You probably want something like this: library(foreign) mydata <- read.spss("c:\\myfolder\\mydata.sav", to.data.frame=TRUE) ----- Original Message ----- From: "UW Email (yunt)" <yunt at u.washington.edu> Date: Tuesday, December 21, 2004 8:17 pm Subject: [R] how do I get my data in matrix form?> Hi, > I am trying to convert the SPSS data that I imported using the > package foreign into a matrix form in R. I tried using > write.table() and cbind() but the output still looks bizzarre. I > have about 104 columns and 21143 rows. Is the size of the the data > causing a problem? > Here was my approach > mydata<-("file location",max=0) > mydata > cbind(mydata) #doesnt work well > write.table(mydata) #distorted output > I also tried data.frame(mydata) #but this gives me only 4 columns > (though properly arranged) > > Is there a better way to resolve this problem? > Thanks > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting- > guide.html
On Tue, 21 Dec 2004 17:17:54 -0800 UW Email \(yunt\) wrote:> Hi, > I am trying to convert the SPSS data that I imported using the package > foreign into a matrix form in R. I tried using write.table() and > cbind() but the output still looks bizzarre. I have about 104 columns > and 21143 rows. Is the size of the the data causing a problem? Here > was my approach > mydata<-("file location",max=0)which gives a syntax error... I guess you meant something like R> mydata <- read.spss("foo") which gives you a "list". If you want a "data.frame" instead (which is probably better than a matrix, you can say R> mydata <- as.data.frame(mydata) or instead you can say R> mydata <- read.spss("foo", to.data.frame = TRUE) in the first place! If you really want a "matrix" then, you can say R> mydata <- as.matrix(mydata) Look at the man pages for more info. Z> mydata > cbind(mydata) #doesnt work well > write.table(mydata) #distorted output > I also tried data.frame(mydata) #but this gives me only 4 columns > (though properly arranged) > > Is there a better way to resolve this problem? > Thanks > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
Reasonably Related Threads
- read.csv does not find my file (windows xp)
- F values from a Repeated Measures aov
- SPSS F-test on change in R square between hierarchical models
- Help with nls and error messages singular gradient
- importing explicitly declared missing values in read.spss (foreign)