I am starting to get a hold on R-language, but I can't seem to be able to create a dataframe which has columns X and rows Y. This is the python code I have written. Need to replicate this in R.
df = pd.read_csv('file.csv')
Cols = pd.unique(df['desiredCol1'])
Rows =pd.unique(df['desiredCol2'])
df2 = pd.DataFrame(index=Rows,columns=pd.unique(Cols))
This is the R code that I have written, but isn't returning desired results.
d= matrix(data = NA, nrow = length(Rows), ncol = length(Cols), byrow = FALSE,
dimnames = list(Rows, Cols))
EDIT: as.data.frame function converts the matrix to a standard R dataframe.
d = as.data.frame(d)