how to store data frame in file
David
It's hard to give direct guidance on your situation because it's unclear what the objects X, dn, and collabs are here. You might start by checking the object structure if you are hitting issues to ensure the object being saved is indeed a data frame:
str(X)
If it is a matrix, you may also convert it to a data frame using
d <- as.data.frame(X)
In general, a data frame "d" can be saved to a file using write.csv:
write.csv(d, file = "folder1/folder2/filename.csv")
I'd recommend also using the row.names = FALSE argument:
write.csv(d, file = "folder1/folder2/filename.csv", row.names = FALSE)
raomohsinkhan
Hi David,
thank you very much for your reply.
I think my R is not working fine.
now I have a code
tow matrix
x and y
x has 4 rows and 1 column
y has 2 rows and 4 column
but when i am trying to multiply x and y it give me error.
what i learnt in school for mutiplying a matrix on matrix column should be equal to other matirx rows.
but it is not working in R
see the code
x = matrix(c(1,2,3,4))
> x
[,1]
[1,] 1
[2,] 2
[3,] 3
[4,] 4
y = matrix(c(3,5,3,1,3,5,1,7), nrow= 2)
> y
[,1] [,2] [,3] [,4]
[1,] 3 3 3 1
[2,] 5 1 5 7
x * y
Error in x * y : non-conformable arrays
> y * x
Error in y * x : non-conformable arrays
I am looking forward to hearing from you soon.
many thanks,
Rao
David
The R help file on matrix multiplication should help clear this up:
https://stat.ethz.ch/R-manual/R-devel/library/base/html/matmult.html
(An internet search can helpful for finding the right R help file if you aren't sure.)
raomohsinkhan
hi there,
i have a data frame in R, now i want to save it on my hard disk (as a file)
how can I do this?
when i am trying to save df in csv file it give me error
Error in dimnames(X) <- list(dn[[1L]], unlist(collabs[nc > 0], use.names = FALSE)) :
length of 'dimnames' [2] not equal to array extent
i want to save df directly in file, is it possible?
thank you
rao