R creates a list, instead of a data frame -


i want write data frame file using write function, doesnt work, because data.frame() creates list.

reproductive example:

data <- data.frame(cbind(1:2,3:4)) typeof(data) data #  x1 x2 #1  1  3 #2  2  4 #> typeof(data) #[1] "list" 

now when want write file using

write(data,"data.txt") 

i error saying

error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot handled 'cat'

which happens because data list, dont understand why list. im running r 3.1.3

actually, data is data.frame:

class(data) # [1] "data.frame" 

the problem write not cope data frames, work matrices:

write(as.matrix(data), "test.txt") 

if want write data frame file use write.table:

write.table(data, "test.txt") 

the error message comes underlying cat function , fact data.frame conceptually list of vectors of same length.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -