I am learning R and have a little knowledge in Python. I feel that R and Python are in some parts alike, and in others very much unalike.
Especially when iterating or reading data from some file, I get stuck.
I have a data.frame
temp <-
A B C
1 2 3
4 5 6
7 8 8
I simply want to read it out, row by row, and write it to a new file.
#New File
[1,2,"3"],
[4,5,"6"],
[7,8,"9"],
I tried this
A <- temp[1]
B <- temp[2]
C <- temp[3]
print(paste("[", A, B, as.character(C), "]", sep = ","))
But, that paste
does not combine A, B
and C
correct. It gives me this:
[1,4,"7"],
[2,5,"8"],
[3,6,"9"],
I tried several other things like
`test <- rbind(temp)`
or
for(i in temp) {
print(temp[,])
print(paste("[", temp[,], "]", sep = ","))
}
and in the end it always comes down to the same thing: It arrays it column by column when I try to print/paste it instead of row by row.
I also fiddled around with array()
. It feels like the right function to do this, but passing list
as the FUN
argument does not seem right...